Have you paid a bill in a vending machine and wondered how the program will change them back? Most likely not, but it turns out that the teacher of Michelangelo was commissioned a program to simulate that, in his own words:
"Suppose a coin machine 10,5,2,1 and 50 cents. You write a program that will decide how many coins you exchange, giving the highest priority designation. You should receive as input the amount of give.Example: for $ 40.50 will be October 4, 0 5, 0 2, 1 and 1 0 of 50 cents. "

So the first problem arises how to input the user to enter only amounts like $ 50 or $ 43.50 and $ 23.45 or amounts as $ 9.70?

So the first problem arises how to input the user to enter only amounts like $ 50 or $ 43.50 and $ 23.45 or amounts as $ 9.70?
What I did is ask for the amount in a float variable (change), another variable that amount to convert int (cambioint). In the process, lose the decimal part of number, so if the change remains - cambiointis equal to 0 or equal to 0.50, the number the user entered is correct.
The other part is simple, only needs to see if the variable rate is above 10. If yes, you subtract 10 to the variable and increases a counter. Then do the same with the other currencies.
But hey, the program is this:
Would lack only give a little formatted output, but it is already a matter of taste and you know, any questions here are the comments below.
0 comments:
Post a Comment