Question
Write a program to dispense change. The user enters the amount paid and the amount due. The program determines how many dollars, quarters, dimes, nickels,
Write a program to dispense change. The user enters the amount paid and the amount due. The program determines how many dollars, quarters, dimes, nickels, and pennies should be given as change. Note that the program should attempt to minimize the number of coins used. For example, if the amount due was $10.00, and the person paid $12.89, the change would be $2.89, where the breakdown would be 2 dollars, 3 quarters, 1 dime, 0 nickels, and 4 pennies.
Write a function called disp_change with four output parameters that determines the quantity of each kind of coin. This function will also return an integer that will store the number of dollars for the change. Using the above example, the function would return 2.
In main, we need to make sure that the use paid enough to cover what was due. If the user pays less than what is due, print a message saying so, and give the user an opportunity to enter the amount paid and due again.
Before coding the disp_change function, think carefully how you will compute the amount of each coin. My recommendation is to first figure out the number of dollars and remove that from the change. Then, figure out the number of quarters and remove that from the change. Repeat this pattern for the remaining coins.
An example of the output is as follows:
Enter the amount due: $6.50
Enter the amount paid: $5.00
You still owe money! Try again.
Enter the amount due: $6.50
Enter the amount paid: $9.43
Your total change is $2.93
Thats 2 dollars, 3 quarters, 1 dimes, 1 nickels, and 2 pennies.
***C++ CODE NOT C****
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started