Money Change Program

I don't get why the bills aren't working, but the coins are... When I enter 50 in, it says 5 tens, which is good, but then it also says 10 fives... But if I enter 50.50 in, then it has the same bill format but then it only says 2 quarters which is right. I think it has to do with the % but I'm not sure what exactly... Help please?

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
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main ()
{

	double money = 0.0;
	double change = 0.0;
	int change1 = 0;
	int tdollars = 0;
	int fdollars = 0;
	int dollars = 0;
	int quarters = 0;
	int dimes = 0;
	int nickels = 0;
	int pennies = 0;


	cout<<"Enter money: $";
	cin>>money;
	cout<<endl;

		change = money;
		change1 = change*100;
		tdollars = change1/1000;
		fdollars = change1/500;
		dollars = change1/100;
		quarters = change1%100/25;
		dimes = change1%100%25/10;
		nickels = change1%100%25%10/5;
		pennies = change1%100%25%10%5;
		
		{
		
		cout<<"Change due: $"<<change<<endl;
		cout<<"Tens: "<<tdollars<<endl;
		cout<<"Fives: "<<fdollars<<endl;
		cout<<"Dollars: "<<dollars<<endl;
		cout<<"Quarters: "<<quarters<<endl;
		cout<<"Dimes: "<<dimes<<endl;
		cout<<"Nickles: "<<nickels<<endl;
		cout<<"Pennies: "<<pennies<<endl;
		cout<<endl;
		cout<<endl;
	}

	system("pause");
	return 0;
}
The code is assigning values to those other dollar note variables that you then cout later.

1
2
3
4
5
6
7
cin>>money; //money=50.50

change = money; //change=50.50
change1 = change*100; //change1=5050
tdollars = change1/1000;  //tdollars=5
fdollars = change1/500;  //fdollars=10
dollars = change1/100;  //dollars=50 


You'll need to account for change you've already given out so it doesn't get counted in what remains to be given in change in the smaller denominations.
Topic archived. No new replies allowed.