Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ code for: Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For

C++ code for:

Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and half-dollar coins.

Your program will use the following function (among others)

void compute_coins(int coin_value,int& num,int& amount_left);

//Precondition: 0

//Postcondition: num has been set equal to the maximum number

//of coins of denomination coin_value cents that can be obtained

//from amount_left. Additionally, amount_left has been decreased

//by the value of the coins, that is, decreased by

/um * coin_value.

(this image is just the same function as listed above, just meant to provide the function since my formatting may be off from posting it )

image text in transcribed

For example, suppose the value of the variable amount_left is 86 . Then, after the following call, the value of number will be 3 and the value of amount_left will be 11 (because if you take 3 quarters from 86 cents, that leaves 11 cents):

compute_coins(25, number, amount_left);

Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program.

( Hint: Use integer division and the % operator to implement this function.)

Additional Requirements (from my class):

-Beginning from Chapter 4, all assignment must contain functions, even if it is possible to do without one.

-If the assignment calls for just a function, you must code a driver to test the function. The driver and the function both must be submitted

-Note: your function must use the function declaration provided by the author.

Thank you :]

void compute coins Cint coin value int& num into amount left) & Precondition: 0 coin value 100; 0 amount 7 eft 100 Postcondition num has been set equa 7 to the maximum number of coins of denomination coin va 7ue cents that can be obtained from amount left. Additionally, amount 7eft has been decreased by the va lue of the coins, that is, decreased by num coin value

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions