cash breakdown formula

hi there!
can somebody help me with a problem i can't seem to solve.

my professor has asked me to create a C++ source file that acts as a cashier in a store. the program should total the amount of items and receives an amount from the user. of course, it will compute for the amount of change to be give.

the only thing i can't seem to handle is the breakdown of the amount of change to be given. it should display the quantity of each bill or coins to be given back as change.

1000 qty:2 amt: 2000
500
200
100
50
20
10
5
1
.25
.10
.5

please help me.
If the amount of change is X dollars and Y cents, then
the number of dollar bills returned is equal to X;
the number of quarters returned is Y / 25;
the number of dimes returned is equal to the amount left over after returning quarters / 10;
etc.


If the amount of change is X dollars and Y cents, then
the number of dollar bills returned is equal to X;
the number of quarters returned is Y / 25;
the number of dimes returned is equal to the amount left over after returning quarters / 10;
etc


its still unclear to me.
lets say the change is 2720.

so there would be 2 thousand bills
1 five hundred
1 two hundred
and a twenty bill.

what would be the formula for that?
How about something along these lines:

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

int main()
{
    int answer;
    int thousands, fhundreds, hundreds...; // you get the idea
    thousands = fhundreds = hundreds ... = 0; 
    
    cout << "Please select a value: ";
    cin >> answer;
    cin.get();
    
    for(int i=1000;answer>=i;thousands++)
      answer-=1000;
    
    for(int i=500;answer>=i;fundreds++)
      answer-=500;
    
    cout << "\nThousands: " << hundreds;
    cout << "\nFive Hundreds: " << tens;

    cout << "Or howecer you want to display the numbers....";

    cin.get();
    return 0;
}

Topic archived. No new replies allowed.