0

For greedy.c in pset1 I used a do...while to validate user input.

But I couldn't see how to loop thru 25, 10, 5, 1 for quarters, dimes, nickels, pennies. I did the exact same calculation 3 times, just with different values, and then another calculation for pennies. When we code the exact same thing multiple times we can use a loop instead, right? But so far in class we've only incremented variables within loops by the same value (i) each time. For a greedy.c loop (i) would have to be 25, then 10, then 5, then 1. Have we learned how to do that yet? Did I miss something? My code passed check50.

1 Answer 1

0

You can't in this case, because there's no easy possible relation between the different values of the coins. If your coins were of values like 40, 20, 10, 5, for example, you could half it. But in this case, there's no easy logic you can use to make it work.

And even if you found a logic that would work in this particular case, you may have to throw the whole code away if you want to deal with a different set of values of coins :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .