Question
Write a function to calculate the number of coins to give as change for a transaction. You have to write a complete C program that
Write a function to calculate the number of coins to give as change for a transaction.
You have to write a complete C program that compiles and runs , but the function is the most important part
The function must: - Receive the following parameters: price of the item including cents, and amount used as payment. - Calculate the number of Dollars, Quarters, Dimes, Nickels, and Pennies, to complete the change amount. - Print the number of each coins value needed to complete the change.
The main must: - Prompt the user for the exact price of the item - Prompt the user for the sum of the bills that will be used for payment - Call the function passing the two values as paramenters. - Prompt the user AGAIN for the exact price of a NEW item (double). - If the user answers with a negative number (-1) then the program ends. - Otherwise you must prompt the user for the sum of the bills that will be used for payment of the NEW item (int) - The main keeps calling the function until the user answer to the exact price is a negative number
Hints: In the function ... 1. Calculate the total number of cents needed for the change. (payment - priceTag) 2. For each type of coin starting with the biggest value calculate the number of coins needed for the change: for instance (numQuarters = numCents / 25) gives you the number of quarters. 3. After each number of coins calculation is completed, calculate the amount of change left, this is the remainder (changeLeft = numCents % 25 )
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