Question: Write a program which tells what coins to give out for any amount of change from 1 cent to 4 dollars and 99 cents. For

Write a program which tells what coins to give out for any amount of change from 1 cent to 4 dollars and 99 cents. For example, if the amount is 2 dollar(s) and 86 cents, then the output would be something like the following:

2 dollars and 86 cents can be given as 11 quarter(s) 1 dime(s) and 1 penny (pennies).

Use coins in denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and half-dollar coins. Your program must use the following functions:

void introduction(); // Postcondition: A description of the program is written on the screen. void getInput(int& dollars, int& cents); // Precondition: User is ready to enter the values correctly. // Postcondition: The value of dollars is set to the number of dollars // the user has and cents is the change the use has.

bool checkInput(int dollars, int cents); // Precondition: Dollars and cents are amounts of money the user enters. // Postcondition: true is returned if the total amount is less than $5; otherwise false is returned.

void determineCoins(int dollars, int cents, int& quarters, int& dimes, int& pennys); // Precondition: Dollars and cents are the user inputs. // Postcondition: quarters has the number of quarters, dimes has the number of dimes and pennys has the number of pennies which add up to the input amount.

void displayOutput(int dollars, int cents, int quarters, int dimes, int pennys); // Precondition: The parameters dollars and cents are the user inputs, and quarters, // dimes and pennys are the computed equivalent amounts. // Postcondition: The values of the parameters are printed to the screen.

The algorithm to determine the coins for the input is:

Compute total number of quarters in the input cents amount. Update cents to be the leftover amount after deducting the value of the quarters. Add to total number of quarters the number of quarters equivalent to the dollarsi amount. Compute the total number of dimes in the cents amount. Update cents after deducting the dimes amount. set pennys to this amount. (Hint: use integer division and the modulus operator to implement this function.)

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

Sample Input and Output:

This program will determine the coin change in quarters, dimes and pennies in your amount of money ($5 or less).

Enter the number of dollars: 2

Enter the amount of change (0 to 99 cents): 86

2 dollar(s) and 86 cents can be given as 11 quarter(s) 1 dime(s) and 1 penny (pennies)

Do you have another amount? (Type y for yes or n for no): y

Enter the number of dollars: 0

Enter the amount of change (0 to 99 cents): 99

99 cents can be given as

3 quarter(s) 2 dime(s) and 4 penny (pennies)

Do you have another amount? (Type y for yes or n for no): y

Enter the number of dollars: 1

Enter the amount of change (0 to 99 cents): 2

1 dollar(s) and 2 cents can be given as 4 quarterk(s) and 2 penny (pennies)

Do you have another amount? (Type y for yes or n for no): y

Enter the number of dollars: 0

Enter the amount of change (0 to 99 cents): 5

0 dollar(s) and 5 cents can be given as 5 penny (pennies)

Do you have another amount? (Type y for yes or n for no): n

Program Requirements:

Use a good consistent indentation scheme and blank lines throughout your program to improve readability.

Carefully choose self-descriptive variable names.

Use a few comments to help explain your program.

You must use the functions and comments described above in your program.

Use const declarations foe the value of the coins.

Use the loop described above in your program.

Carefully test your program and be sure that it executes on the EECS system.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!