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.
1 Answer
Instead of dividing, try subtracting the values of the respective coins from dollars withing your while loops, e.g. dollars = dollars - quarters.
-
-
1Remove 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_kratSep 20, 2014 at 23:08