### stopping code with input and if statment

What is wrong with this?? Why is it that when I enter 999 to the first question it goes ahead and asks the next question instead of stopping the code and spitting out the proper statement.

I haven't been coding for about a year... haha..

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879`` ``````#include #include using namespace std; int main() { cout << " name here " << endl; cout << " date here " << endl; cout << " Program 5 " << endl; cout << " The Change Machine " << endl; cout << endl; cout << " This program will take the purchase amount and the amount of cash given as input. \n" << " Then it will tell you how much change to give in the most efficent way possible. \n When you are done using the Change Machine enter 999 and the program will stop running." << endl; cout << setprecision(2) << fixed; float cash, cost; do { cout << " Enter the total cost: " << endl; cin >> cost; if(cost == 999) { cout << " Thank you for using the Change Calculator! Have a nice day! " << endl; } else if(cost != 999) { cout << " Total: \$" << cost << endl; //Prints the cost back to the user to make sure it is correct. cout << endl; cout << " Enter the cash given: " << endl; cin >> cash; cout << " Cash: \$" << cash << endl; //Prints the amount of cash given to make sure it is correct. float totchange; totchange = cash - cost; //Tells us the amount of change total. cout << endl; if(totchange < 0.00) { cout << " Please give the cashier more money. " << endl << endl; } else if(totchange == 0.00) { cout << " There is no change due. " << endl << endl; } else if(totchange >= 0.01) { cout << " Total Change: \$" << totchange << endl; cout << endl; int total; //I am taking the total and multiplying by 100 to get rid of total = totchange * 100; // The decimal. Once I divide I multiply the answer int dollars; // by 100 to subtract the amount that would be given back dollars = total / 100; // In dollars. Then I continue the same process int aTotal; // but I divide by the amount of the coin and then multiply back aTotal = total - (dollars * 100); // so that I can subtract it from the total int quarters; // and so on! quarters = aTotal / 25; int bTotal; bTotal = aTotal - (quarters * 25); int dimes; dimes = bTotal / 10; int cTotal; cTotal = bTotal - (dimes * 10); int nickels; nickels = cTotal / 5; int dTotal; dTotal = cTotal - (nickels * 5); int pennies; pennies = dTotal / 1; cout << " Change: " << endl; cout << "\t\t" << dollars << "\t Dollars " << endl; cout << "\t\t" << quarters << "\t Quarters " << endl; cout << "\t\t" << dimes << "\t Dimes " << endl; cout << "\t\t" << nickels << "\t Nickels " << endl; cout << "\t\t" << pennies << "\t Pennies " << endl; cout << endl; } } } while(cost != 999); } ``````
Last edited on
Also I know I've got some issues here. I noticed if there is a penny for change the program screws up. I haven't completely looked into all the errors with the code yet. I am reviewing programs I had to write for college last spring semester. I'll get to other things later. My main focus is figuring out what I need to do to make the code stop if someone enters in "999" to the first question.
Registered users can post here. Sign in or register to post.