I need to create a script that asks the user for a $ amount and then outputs the minimum amount of coins to create that $ amount using quarters, dimes, nickels, and pennies.
mTotal = (float(input("Enter the amount you are owed in $:")))
numCoins = 0
while (mTotal != 0):
if ((mTotal - 0.25) >= 0):
mTotal-=0.25
numCoins += 1
elif ((mTotal - 0.10)>= 0):
mTotal-=0.10
numCoins += 1
elif ((mTotal - 0.05)>= 0):
mTotal-=0.05
numCoins += 1
elif ((mTotal - 0.01)>= 0):
mTotal-=0.01
numCoins += 1
print("The minimum number of coins the cashier can return is:", numCoins)
For some reason it only works if I enter 0.01, 0.05, 0.10 or an exact multiple of 0.25, otherwise the while loop goes on forever.