|
I have an array:int amounts[]
How do I define size of arrays as an enumeration literal
Num in an anonymous enumeration?
|
|
|
|
|
Typically when I need to do this I have:
enum Test
{
Item 1
Item 2
.
.
.
Item N
TestEnd
}
then I just use (TestEnd - Item 1) for the size on the array. Just make sure that if you add to the enumeration that TestEnd or whatever you call it is always the last item. This will create a proper sized array.
|
|
|
|
|
Here is my code:
Can you help me?
#include <iostream>
using namespace std;
const NUM = 2;
int volumes[NUM], volume;
int count=0;
int amounts[NUM],amount;
const double price=0.05;
const double fee=12.0;
int main()
{
do
{
cout<<"Please enter the volume of water used by a customer ";
cout<< "during a month (in gallons).(Zero to end):";
cin>>volume;
if (volume==0.0)
break;
if (count==NUM)
break;
volumes[count++]=volume;
amount=(volume*price)+fee;
amounts[count++]=amount;
}
while(true);
return 0;
}
|
|
|
|
|
// include <float.h> and <iostream> in stdafx.h
#include "stdafx.h"
using namespace std;
const NUM = 2;
// changed int to double because volume usually isn't in whole numbers
//int volumes[NUM], volume;
double volumes[NUM], volume;
int count=0;
// use double for amounts because you are using doubles to multiply
double amounts[NUM],amount;
const double price=0.05;
const double fee=12.0;
int main()
{
do
{
cout<<"Please enter the volume of water used by a customer ";
// cout won't get you the value must use cin
//cout<volume;
cin="">> volume;
// with doubles never check for equality, check for greater or
// less than
if (volume < DBL_MIN )
break;
// move this check to the end of the while loop
// and make it check for >= instead of ==
//if (count==NUM)
// break;
// also you are incrementing count twice. only do it once
//volumes[count++]=volume;
amount=(volume*price)+fee;
//amounts[count++]=amount;
volumes[count] = volume;
amounts[count] = amount;
count++;
if( count >= NUM )
break;
}
while(true);
return 0;
}
|
|
|
|
|
Thanks for the comments. It helps a lot.
One more question:
I am trying to display all values after user enters 0. I wrote the following code. I can't see what is incorrect in this code.
displayArray();
void displayArray(const int volumes[NUM];const int NUM)
{
count<<"\n";
int count=0;
while (count
|
|
|
|
|
Also don't forget to predefine the function unless you put the fuction code before main.
displayArray( volumes, count);
// First the Function declaration is incorrect.
// you have a semicolon where there should be a comma
// and you have volumes declared as int when it should be
// double but that was covered previously
// also you don't need NUM as a variable because it is a
// program constant. Instead pass Count
//void displayArray( const int volumes[NUM]; const int NUM)
void displayArray( const double volumes[NUM], const int Count)
{
cout<<"\n";
int nCount=0;
while ( nCount < Count)
{
cout<< volumes[nCount] << " ";
nCount++;
}
int nPause;
cin >> nPause;
}
|
|
|
|
|
Thank you for comments it explains a lot (I am in school )
|
|
|
|
|
Hello, everyone!
How to dump some debug information (I mean the information of my special program information, for example, the value of a variable which I am interested in) to VC 6.0's debug window in a MFC project? Who can show me an example?
Thanks in advance,
George
|
|
|
|
|
afxDump << nVar;
afxDump is the stream that outputs to the debug window in the Visual Studio IDE. It works in both 5.0, 6.0 and .NET.
|
|
|
|
|
Thanks, Adam buddy!
George
|
|
|
|
|
Search MSDN for the TRACE() macros.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks, DavidCrow buddy!
George
|
|
|
|
|
A good utility for using the trace functionality in your application so that you can also send to a different viewer (for more real time debugging) go here http://www.dilascia.com/
and get the Trace Win app.
|
|
|
|
|
Thanks, Adam buddy!
George
|
|
|
|
|
Hi All,
How can I implement in VC++ a function like VB CreateObject Function.
I've make a Dll in VB with 3 classes how can I invoke those classes in VC++
Thank in Advance
CM
Carlos Mariano
|
|
|
|
|
Hy,
i hope somebody can help me to solve my problem.
I have a laptop and a lan network at my company and a lan network
at home.
At home i have a static ip address for my laptop ,
at company the ip address is given dynamicly.
I would like to write a little tool to change the ip address
and the setting how to receive the ip address,
to make the change more comfartable for me.
I know there exist some tools to do exactly this, but i want to
solve this problem on my own.
Now i am searching for examples or the orders to implement my tool,
because i do not find them until now.
I am very thankful for every advice.
Thanks
Micha
|
|
|
|
|
What is the purpose of changing dynamic IP?
In any case, you may consider creating local DNS mapping just by opening and writing/modifying new entry in "Hosts" file located in yours WINDOWS\SYSTEM32 directory. Make sure to do that before loading/calling any winsock/wininet functions in your program.
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
I have a Video system and I want to display permanently images that come from it when I run my application. Solution seems to be Direct Draw with 2 graphic board or a DUAL one. It is not really a problem, I suceed. But, there is a point that worry me. It is obvious that when my application is running on one monitor we will display video image and on the other normal interface and I'd like seeing mouse only on the normal inteface. But if we attach all the graphical boards to the desktop the mouse is moving on the 2 screen, I am afraid that is too confusing for customer. I'd like then use one board attach on the desktop (we need at least one anyway) and the other is sleeping, excepted when my application is running then it will display video. In term of programing that means we need to call Direct draw with the good board device. the function DirectDrawEnumerateEx is all what we need. It works well if all the board are attached to the desktop (that is to say we see all the board device) but any of the boards are not attached then I don't succeed in seeing them. However there is a flag DDENUM_DETACHEDSECONDARYDEVICES that seems to be specially provided for that use but it do not return anything about the detached devices. Is anyone can help?
Gwen
|
|
|
|
|
Hi there,
I have some MFC programs, which worked without a problem unter Windows NT.
But now I have Windows 2000 and when i change the resolution down to 640x480..the MFC Program doesn't change the own resolution?
What's wrong with my programs?
Thanks!
cheers
|
|
|
|
|
Hi,
In my VC++ server application ,i create a Process.I want to kill this Process after say 10 or 15 minutes if the Process is Ideal(in this case if the client/User doesn't connect to the server).Pls help.
I know that i can use KillProcess .But how to find the Process is ideal(that's if user is not connecting to server)
Thnks in advance
ram
|
|
|
|
|
When you created the process via CreateProcess() , the last parameter will contain the process' handle. Keep that handle around for use later on.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi !
Is it possible to create a CWnd which would have it's client area look like a dialog resource ?
Why ? Because CDialog class doesn't have a great support for menus, docking toolbars or other stuff a CWnd has.. CFormView is the closest thing to what I want to achieve (CFrameWnd with CFormView as the view), but I do not want to use the document template. And using a CFormView without a document template is daunting process (read: I have no clue how)
In addition to all this, my dialog MUST have a classname as well..
So, any suggestions on where to begin ? Namely, how to bind a dialog template to a CWnd
Thanks,
Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
You MUST not use the doc, you code your programm around. It only helps you with some routines.
Another approach can be the modeless dialog. There are some samples in the MSDN and maybe in CP.
Try this @ home. (B&B)
|
|
|
|
|
Thanks for the reply !
Unfortunately, I couldn't find any ways to 'code this around'.. Any hints on where I could find such articles ?
Like I described in my opening post, using a CDialog-derived class is NOT an option, unless you can tell me how I can specify a menu resource, a class name and a window name while building the dialog. Does the CDialog have a suitable overridden CWnd::Create for this purpose ?
Greets,
Antti
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
The application I work on can be ran through an automation model via DCOM, which is fine and works well, but it does mean that we must be able to run several instances of the application on one machine. I've found that I can run no more then 10 instances of the application on any given machine (regardless of the resources available to the machine), and this simply isn't enough, so I've been looking into why this is.
I've found that if I create a standard MFC (VC6) MDI app, accepting all the defaults, that that application can only be ran 102 times simultaneously, which seems very odd to me, the machine (according to task manager on WinXP) has plenty of memory available, but I can't open another instance of the application (or any other application, like notepad). When I trace into it with the IDE I find that it either fails on creating the main frame of loading the main menu resource.
So, I was wondering, does anyone know if there is a limit to the amount of resource's / GDI objects / USER objects / handles / threads Windows can open at once? Or am I barking up the wrong tree - can anyone give me a clue as to how I can get my app to run more simultaneous copies? (Note, I can't change the architecture at this stage, I'm stuck with the automation model, management's decision...)
Dylan
|
|
|
|