0
Can anyone explain how to write a modulus formula that would tell me how many 20, 10 and 5 dollar bills i would get uf i gave someone$75? Thanks
6 Réponses
+ 6
Yes.
// If one or more twenties can be given out, figure
// out how many and how much is still needed.
if (money >= 20) {
twenties = money / 20;
money %= 20;
}
Given money of 75, twenties is set to 3 and money is changed to 15. Do the same for 10, 5, 1, .50, .25, .10, .05, & .01 and you got a universal change program.
+ 6
(1) How many 20 dollar bill(s) do I need for $75?
floor(75 / 20) = 3
(2) What is the remaining amount do I need to pay?
$(75 - 3 * 20) = $15
(3) How many $10 dollar bill(s) do I need for $15?
floor(15 / 10) = 1
(4) What is the remaining amount do I need to pay?
$(15 - 1 * 10) = $5
(5) How many $5 dollar bill(s) do I need for $5?
floor(5 / 5) = 1
(6) What is the remaining amount do I need to pay?
$(5 - 5) = $0
(7) [3 × $20, 1 × $10, 1 × $5]
+ 4
cost = 275
array[100,50,20,10,5,1]
for each value in array do
count = cost modulo value
if count larger than zero
cost = cost - (value * count)
print count on the screen
end cost > value
end for each value
Hth, cmiiw
+ 2
Copy the if statement, paste it afterwards, and change the three 20's to 10. Repeat as needed.
0
I just can't wrap my head around how to continue the calculation. I understand how to get the first bit, money = 75, money % 20 = 15. Now how does one continue that, do I just go on with money %10= 5 ?