Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*all i need is a running start on this Create a function that will calculate the

ID: 3620924 • Letter: #

Question

 

*all i need is a running start on this

 

Create a function that will calculate the correct change to be returned to the customer (in terms of how many $20’s, $10’s, $5’s, $1’s, quarters, dimes, nickels and pennies). The total bill can paid in any mix of the above currency. For this lab no bill will total more that $200.

Lab Procedure:
1. Build and demonstrate a program that:
a. Calls a function to calculate the amount of currency paid.
b. Calculates the amount of change.
2. Call a function that will calculate the number of each currency denomination to use to make exact change.

Explanation / Answer

This function will just be a combo of division and mod operators. For example, if the amount paid is $55. First 55.5 divided by 20 (ignore remainder for now) gives two 20 dollar bills. Then 55 mod 20 (55-(20x2)) give 15.5. Now pass the 15 down. 15.5 divided by 10 is 1 so one ten dollar bill. 15.5 mod 10 is 5.5. Pass 5.5 down. 5.5 divided by 1 is 5. 5.5 mod 1 if .5. .5 divided by.25 is 2. .5 mod .25 is 0. You're done. For dimes and dimes, nickels, and pennies just continue with .1, .05 and .01.