bills and coins program

Hey guys, im making a program that takes a number and tells you how much bills and coins you have in 500 - 100 - 50 - 20 - 10 - 5 - 2 - 1.

For some reason...it takes the number and writes 0 everywhere....anybody knows why?
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
#include<iostream>
#include<cmath>

using namespace std;

int main()

{

	int x;

	

	cout << "Enter amount of money" << endl;
	cin >> x;

	cout << (x%500) << "of 500 bills" << endl <<
		(x % 500) % 100 << "of 100 bills" << endl <<
		((x % 500) % 100) % 50 << "of 50 bills" << endl <<
		(((x % 500) % 100) % 50) % 20 << "of 20 bills" << endl <<
		((((x % 500) % 100) % 50) % 20) % 10 << "of 10 coins" << endl <<
		(((((x % 500) % 100) % 50) % 20) % 10) % 5 << "of 5 coins" << endl <<
		((((((x % 500) % 100) % 50) % 20) % 10) % 5) % 2 << "of 2 coins" << endl <<
		(((((((x % 500) % 100) % 50) % 20) % 10) % 5) % 2) % 1 << "of 1 coins" << endl;

	return 0;



}
You may be getting 0's from integer division. But I think the formula above is off for what you're trying to achieve.

If you enter 650 as x, that would be one 500 bill, one 100 bill and one 50 bill.

650 % 500 is going to be 150. That's the amount left after you account for one 500 bill, not the number of 500 bills.
Topic archived. No new replies allowed.