Fewest number of bills program

I think I'm mostly stuck on the math, but I can't figure out what I'm doing wrong. I'm trying to make a program that will let the user enter an amount of money and get the fewest amount of bills that adds up to the number back. Program doesn't have to be unbreakable and shouldn't take integers but also doesn't tell the user when they entered an integer.

I've looked at videos online, other forums... I just can't find anything that deals with just dollars, not dollars and coins.

The big problem is that this program does tell how much money is needed for each dollar, but the numbers don't consider each other and add up correctly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        double money;
	int result;

	cout << "Enter a dollar amount: ";
	cin >> money;

	result = money;

	cout << "The fewest number of bills to get " << money << " is:\n";

	cout << "=========================================\n";

	result = result % 20;
	cout << "$20 bills: " << result / 20 << "\n";
	result = result % 10;
	cout << "$10 bills: " << result / 10 << "\n";
	result = result % 5;
	cout << "$5 bills : " << result / 5 << "\n";
	result = result % 1;
	cout << "$1 bills : " << result / 1 << "\n";


Last edited on
Please do not double-post. Other thread: http://www.cplusplus.com/forum/beginner/242751/
Sorry, I'm new on here. How do I delete this post? The other one that was solved I'll keep up.
Topic archived. No new replies allowed.