Answer:
amount_due = float(input("Enter amount due: "))
amount_paid = float(input("Enter amount paid: "))
change = amount_paid - amount_due
pennies = change * 100
quarters = int(pennies / 25)
pennies %= 25
dimes = int(pennies / 10)
pennies %= 10
nickels = int(pennies / 5)
pennies %= 5
pennies = int(pennies)
print("Your change is $%.2f" % change)
print("Quarters: " + str(quarters) + ", Dimes: " + str(dimes) + ", Nickels: " + str(nickels) + ", Pennies: " + str(pennies))
Step-by-step explanation:
*The code is in Python.
Ask the user to enter amount due and amount paid
Calculate the change
Convert change to pennies
Find the number of quarters, dimes, nickels in the pennies using division and modular operator. The remaining amount equals the number of pennies
Print the change
Print the number of quarters, dimes, nickels, and pennies
Let me demonstrate calculating the quarters:
Let's say pennies equals 39,
quarters = int(pennies / 25) → int(39/35) → int(1.11) = 1
pennies %= 25 (same as pennies = pennies % 25) → 39 % 25 → 14