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..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <iomanip>

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.
Topic archived. No new replies allowed.