Cashier Program question

I am trying to create a program that would help a cashier return change to their customer, it will print out how many hundreds, tens, fives, ones, quarters, dimes, nickels, and pennies.

I am stuck on the quarter part, I can't seem to figure out to print out the correct amount of quarters needed. If i make the quarter a double, it will print out that I need 3.12 quarters (something along the lines of that) and if I make the quarter variable and int, it will sometimes print out that I need 0 quarters.

P.S. I realize I forgot to add the code to return the number of five dollar bills, I will do that later tonight.

Does anyone have any suggestions?

Thanks

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
#include <iostream>
using namespace std;

void changeFunction(double &change)
{
	int hundreds;
	int tens;
	int fives;
	int ones;
	double quarters;
	double dimes;
	double nickles;
	double pennies;

	if (change < 100)
	{
		tens = change / 10;
		cout << "The number of tens you will need is: " << tens << endl;

		ones = change - (tens * 10);
		cout << "The number of ones you will need is: " << ones << endl;

		quarters = change - ((tens * 10) + (ones * 1));
		quarters = quarters*100;
		quarters = quarters / 25;
		cout << "The number of quarters you will need is: " << quarters;

	}

	if (change >= 100)
	{
		hundreds = change / 100;
		cout << "The number of hundreds you will need is:" << hundreds << endl;

		tens = (change-(hundreds*100)) / 10;
		cout << "The number of tens you will need is:" << tens << endl;

		ones = change - (hundreds * 100 + tens * 10);
		cout << "The numner of ones you will need is:" << ones << endl;
	}

}

int main()

{
	double change;

	cout << "Enter a value of money that needs to broken down into change: ";
	cin >> change;


	changeFunction(change);

	system("pause");
	return 0;
}
Use the %, modulo. It gives the rest of the /

so if you have 87 cent
You do:

87 / 25 = 3.48, so 3 quarter

you do
87 % 25 = 12 (.48 *25)

repeat.

12/ 10 = 1 dime

....
Thank you @Mark2
Topic archived. No new replies allowed.