SOLUTION FILE AVAILABLE AT: http://libraay.com/downloads/candy-store-cashier-algorithm/
Problem:
Design an algorithm for the following problem: You are a cashier in a candy store. Each of your customers buys exactly one item costing $1.00 or less. Each customers pays for the item with exactly $1.00. Your job is to give each customer the correct amount of change in some combination of pennies, nickels, dimes, and quarters. The combination must be the minimum number of coins. For example, if the item cost is $.38, the change would be 2 quarters, 1 dime, 0 nickels, and 2 pennies ($.62). The input is composed of customer records, each containing customer name and item cost. The output is composed of lines, each containing customer name, item cost, change, number of quarters, number of dimes, number of nickels, and number of pennies. A cost of $0.00 will be used to signal the end of the input.
Solution:
Begin
Prompt “Enter name, cost”
Input name, cost
Do While cost > 0
quarter = 0
dime = 0
nickel = 0
penny = 0
change = 1 – cost
changep = change
Do While change >= 0.25
change = change – 0.25
quarter = quarter + 1
End While
Do While change >= 0.10
change = change – 0.10
dime = dime + 1
End While
Do While change >= 0.05
change = change – 0.05
nickel = nickel + 1
End While
Do While change > 0
change = change – 0.01
penny = penny + 1
End While
Print “Customer Name: “, name
Print “Cost of Item: “, cost
Print “Change: “, changep
Print “Number of quarters: “, quarter
Print “Number of dimes: “, dime
Print “Number of nickels: “, nickel
Print “Number of pennies: “, penny
Print “——————————-”
Prompt name, cost
End While
SOLUTION FILE AVAILABLE AT: http://libraay.com/downloads/candy-store-cashier-algorithm/