-
coin change program??
For some reason, I cannot think of the algorithm behind making this program. I have thought it through several times; however, it just doesn't make sense. Could someone lead my through the program, by means of some seudocode or actual code or something? Thanks
-
Perhaps you could specify what your program needs to do in more detail and I'll try to help out with an algorithm.
-Prelude
-
Well, for example if the program promted the user to enter an amount like 95 cents, the program would display 3 quartes, and 2 dimes, which is the most efficient way of giving change. IF the user enters more than 99 cents, it will give the user en error and loop.
-
Code:
IF value <= 99
WHILE value > 0
IF value >= 25
quarters = quarters + 1
value = value - 25
ELSE IF value >= 10
dimes = dimes + 1
value = value - 10
ELSE IF value >= 5
nickels = nickels + 1
value = value - 5
ELSE
pennies = pennies + 1
value = value - 1
LOOP
ELSE
PRINT error message
-Prelude