0

I don't understand what is going on with my code for greedy. When I nest while loops for quarters and dimes, it gives me the right amount of coins used, but when I increase a similar while loop for nickels and pennies it keeps prompting me for a value.

0

Instead of dividing, try subtracting the values of the respective coins from dollars withing your while loops, e.g. dollars = dollars - quarters.

2
  • still doing the same thing.the terminal keeps prompting – Yeku Wilfred Chetat Sep 20 '14 at 23:01
  • 1
    Remove the curly braces before the first while loop, i.e. after your do/while loop at the beginning, so that all your while loops are not embedded in extra curly braces. You can add an if statement before each of the while loops, so that the respective while loops are only entered if those if conditions are met, e.g. if (dollars => 25) before while (dollars => 25). – pat_krat Sep 20 '14 at 23:08

You must log in to answer this question.

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