Change maker problem-change (1-99 cents), allows repeated calculation:
// Change maker problem-change (1-99 cents) # include <iostream> using namespace STD; void compute_coins (INT coin_value, Int & number, Int & amount_left); int main () {int cents, number [2], amount_left; char ans; do {cout <"Enter the (1-99) cents: \ n"; CIN> cents; number [0] = number [1] = number [2] = {0}; amount_left = cents; while (amount_left> 0) {If (amount_left> = 25) {compute_coins (25, number [0], amount_left); compute_coins (10, number [1], amount_left); compute_coins (1, number [2], amount_left);} else if (amount_left> = 10 & amount_left <25) {compute_coins (10, number [1], amount_left); compute_coins (1, number [2], amount_left);} else if (amount_left> = 1 & amount_left <10) compute_coins (1, number [2], amount_left );} cout <cents <"cents can be given as" <Endl <number [0] <"quarter (s) "<number [1] <" dime (s) and "<number [2] <"Penny (pennies)" <Endl; cout <"do you want again? "; CIN> ans;} while ('y' = ans | 'y' = ans);} void compute_coins (INT coin_value, Int & number, int & amount_left) {Switch (coin_value) {Case 25: Number = amount_left/25; amount_left = amount_left % coin_value; break; case 10: Number = amount_left/10; amount_left = amount_left % coin_value; break; Case 1: Number = amount_left/1; amount_left = amount_left % coin_value; break; default: cout <"error! ";}}
Result:
Enter the (1-99)cents:8686 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies)Do you want again?yEnter the (1-99)cents:2525 cents can be given as 1 quarter(s) 0 dime(s) and 0 penny(pennies)Do you want again?yEnter the (1-99)cents:1010 cents can be given as 0 quarter(s) 1 dime(s) and 0 penny(pennies)Do you want again?yEnter the (1-99)cents:11 cents can be given as 0 quarter(s) 0 dime(s) and 1 penny(pennies)Do you want again?
Change maker problem-0 (1-99 cents)