|
It's hard to read in this format, but I think there is more wrong than just this function.
Your dispenseChange functions accepts a double m, which contains the amount of money inserted. The function is called when the amount is more than 1.00. The price of a drink is 25ct, so why not call this function when the amount is more than 0.25?
Then when you're in the function dispenseChange, you call GetMoney. So after you have inserted too much money already and change is calculated, you ask for another coin to be inserted and then base the change on that coin.
The change should be based on the amount paid and the price: so m-0.25 is the amount that is paid too much. Then you'd have to split this to coins.
Other observations:
In your main loop, you check until you have inserted enough money. You do this by calling getMoney(), but you don't update your money variable. So the enough(money) check won't be right either.
Your getDrink function calls itself.
Maybe try something like this:
using namespace std;
void banner();
void menu();
int getMoney();
bool enough(double);
void getDrink();
void dispenseChange(double);
int main ()
{
double money = 0.0;
banner();
menu();
while (!enough(money))
{
switch (getMoney())
{
case 1: cout << "You have entered $1.00" << endl;
money += 1.00;
break;
case 2: cout << "You have entered 25 cents" << endl;
money += 0.25;
break;
case 3: cout << "You have entered 10 cents" << endl;
money += 0.10;
break;
case 4: cout << "You have entered 5 cents" << endl;
money += 0.05;
break;
}
cout << endl << "Current amount deposited is " << money << endl;
}
getDrink();
if (money > 0.25)
dispenseChange(money);
return 0;
}
void banner()
{
cout << "MMM DDD" << endl
<< "OOO EEE" << endl
<< "UUU WWW" << endl
<< "NNN " << endl
<< "TTT " << endl
<< "AAA " << endl
<< "III " << endl
<< "NNN " << endl;
}
void menu()
{
cout << "Pick your drink" << endl
<< "1. Pepsi" << endl
<< "2. Diet Pepsi" << endl
<< "3. Mountain Dew" << endl
<< "4. Diet Mountain Dew" << endl
<< "5. Bottled Water" << endl;
}
int getMoney()
{
int opt;
cout << "Please deposit $0.25." << endl;
cout << "1.Dollar" << endl
<< "2.Quarter" << endl
<< "3.Dime" << endl
<< "4.Nickel" << endl;
cin >> opt;
return opt;
}
bool enough(double m)
{
if (m >= 0.25){
cout << "Enough money inserted" << endl;
return 1;
}
else{
cout << "Need more money" << endl;
return 0;
}
}
void getDrink()
{
int option;
cout << "Pick your drink" << endl;
cout << "1.Pepsi" << endl
<< "2.Diet Pepsi" << endl
<< "3.Mountain Dew" << endl
<< "4.Diet Mountain Dew" << endl
<< "5.Bottled Water" << endl;
cin >> option;
cout << "Here is your drink" << endl;
}
void dispenseChange(double m)
{
if (m == 1.20)
cout << "Your change is $0.95 or 3 quarters and 2 dimes.";
else if (m == 1.15)
cout << "Your change is $0.90 or 3 quarters and a dime and a nickel.";
else if (m == 1.10)
cout << "Your change is $0.85 or 3 quarters and a dime.";
else if (m == 1.05)
cout << "Your change is $0.80 or 3 quarters and a nickel.";
else if (m == 1.00)
cout << "Your change is $0.75 or 3 quarters.";
else if (m == 0.45)
cout << "Your change is $0.20 or 2 dimes.";
else if (m == 0.40)
cout << "Your change is $0.15 or a dime and a nickel.";
else if (m == 0.35)
cout << "Your change is $0.10 or a dime.";
else if (m == 0.30)
cout << "Your change is $0.05 or a nickel.";
}
modified on Saturday, December 4, 2010 6:40 AM
modified 13-Sep-18 21:01pm.
|
|
|
|
|
you get mixed up betwen "=" and "==" ...
review your courses texts and documentations.
Watched code never compiles.
|
|
|
|
|
To open a drive/disk and read data from it there are many ways like CreateFile/ReadFile, _open/_read etc
do we have any code written in assembly language which open disk and read data from it from any location. And we can use that code in vc++. If yes please provide any link
|
|
|
|
|
You are not going to improve performance by writing assembly code to read/write files, because there's a bigger bottleneck at the disk i/o level (the data transfer from/to the disk happens at a MUCH slower pace than the speed at which the program itself executes).
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
ok. What about data reading. Using VC++ function sometime API hangs which read data. Will assembly code success in this. And to read data asynchronously is not reliable because it depends on disk to disk.
|
|
|
|
|
There's no reason why a C++ API should "hang" as such while reading a file. It may be due to disk latency, which cannot be cured if you change the programming language that was used to read data.
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
|
Don't bother trying to use assembly language for this type of thing. Under modern operating systems you're always going to have to use some OS service to access the disk whatever language you're programming in. Even if you write a device driver to do the access there's no point in using an assembly language as writing it in C will be easier and probably as fast and efficient. And even if you write a device driver you're still relying on the OS to call the driver for you so you're still at the mercy of the OS.
Cheers,
Ash
|
|
|
|
|
Thanks
I experienced that asynchronous disk io is not reliable. Am i correct?
If not then please give some idea about the way to use it
|
|
|
|
|
What do you mean with "reliable" ?!?
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
it is known to occasionally return bits that are neither one nor zero.
|
|
|
|
|
Hi there,
I need to use a memory checker "like" Intel Memory Inspector.
Of course I do'nt have 800 USD to buy such tool so I wonder if there are alternatives ?
Push Framework - now released !
http://www.pushframework.com
|
|
|
|
|
|
Hi all,
I'm stuck with this.
I want to find the memory usage of my application. So I can work on with GetProcessMemoryInfo, and I need to find the relevant process ID in-advance to workaround. It's possible too.
But if my application runs multiple instances I cannot do that. Because all the process has the same name I cannot pick what the ID is.
Any suggestions really appreciate.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
You could use the GetCurrentProcess[^] function and pass it to GetProcessMemoryInfo[^].
HANDLE hProc = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS_EX info;
info.cb = sizeof(PROCESS_MEMORY_COUNTERS_EX);
GetProcessMemoryInfo(hProc, (PROCESS_MEMORY_COUNTERS*)&info, info.cb);
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Thanks for the replay.
Actually I comes with an error, undeclared identifier on the following.
Thaddeus Jones wrote: PROCESS_MEMORY_COUNTERS_EX info;
I've included psapi.h header too.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
You can try PROCESS_MEMORY_COUNTERS instead, maybe PROCESS_MEMORY_COUNTERS_EX was introduced later than your compiler (it requires WinXP SP2 or above).
modified 13-Sep-18 21:01pm.
|
|
|
|
|
That's why I'm wired. I'm working on WinXP SP3.
Anyway I work on with PROCESS_MEMORY_COUNTERS, and works fine. But when I'm invoking GetProcessMemoryInfo(...) it gives an unusual error at build.
error LNK2019: unresolved external symbol _GetProcessMemoryInfo@12 referenced in function "public: void __thiscall CMyExceptionLogger::LogMemoryUsage(enum LOGLEVEL)" (?LogMemoryUsage@CMyExceptionLogger@@QAEXW4LOGLEVEL@@@Z)
You have any idea about this?
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Did you link psapi.lib to your project?
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Oh no. I don't. Could you please guide me how to do that?
I appreciate your help all the time...
CodingLover
|
|
|
|
|
That varies per compiler, you'd have to look that up in the manual.
Typically there's a menu item named Project with subitem Settings or Configuration or something.
modified on Monday, December 6, 2010 8:25 AM
modified 13-Sep-18 21:01pm.
|
|
|
|
|
As replied, you can use GetCurrentProcess to get a handle to the current process.
But this is a pseudo-handle and its value is always -1 .
This handle is not valid outside of the current process.
If you want to pass the handle to another process, you can call DuplicateHandle on this pseudo-handle to get a real one.
|
|
|
|
|
Hi
How to convert a CString value to HEX?
eg:
CString strHex = "0008103e";
to
HEX value = 0x0008103e
please help
Thanks
|
|
|
|
|
An hex value doesn't exist, what you want probably is to convert a string representing an integer in hexadecimal notation to an integer. For this you can use strtol[^] function.
|
|
|
|
|
Benjamin Bruno wrote: How to convert a CString value to HEX?
eg:
CString strHex = "0008103e";
to
HEX value = 0x0008103e
What Cedric said.
ULONG nVal;
CString str = _T("0x4335");
nVal = _tcstol(str, NULL, 0);
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|