# Change maker problem-0 (1-99 cents)

Source: Internet
Author: User

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)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.