function that takes coins away from a change amount

I have completed the rest of my code but I cant make a function that allows an input value CHANGE, to be calculated in coins.

Example:

input 184 cents to make change for.

Takes the least amount of coins (Quarters, dimes, nickels, pennies from the amount inputted into a struct called coinbox)

So for 184 it should be

7 quarters
1 nickel
4 pennies




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
void make_change (coinbox& c, int amount)
{
     int change;
     change=0;
     int quarter, dime, nickel, penny;
     quarter=25;
     dime=10;
     nickel=5;
     penny=1;
     
     cout << "Enter the amount to make change for: ";
     cin >> change;
     cout << "\n\n";
     
     amount=change/quarter;
     if(amount>=c.quarters)
     {amount=change/c.quarters*quarter;
     c.quarters==change/c.quarters*quarter;}
     cout << amount << endl;
     
     
     
     
     
     
     
    
     
     
     
     
     
     cout << "Change made: "<< endl;
     cout << "   Quarters: "<< c.quarters << endl;
     cout << "   Dimes: "<< c.dimes << endl;
     cout << "   Nickels: " << c.nickels << endl;
     cout << "   Pennies: " << c.pennies << endl;
     cout << endl;
     cout << endl;
     
     
     }
Last edited on
Try making your own and post what you got. Part of being a programmer is solving algorithms.
Sorry, thank you. I've been trying to do this for a while thats why I am asking
Topic archived. No new replies allowed.