This to me looks like it would compile and output correctly but I'm clearly missing something as it gives me nothing. The user input is working but the loops aren't (as in I'm getting user input, converting, rounding so I didn't include that first part of my code). Why doesn't at least print something even if it's wrong?

Greedy code


You have an infinite loop. OK, you have 4 of them. Look at your quarters loop:


The while loop will only terminate when change drops below 25. However, you never alter the value of change in the loop. The result is that if you ever start the loop, i.e., if change really is >= 25, it will never exit. Same problem with dimes, nickels and pennies.

Fixing those loops will get you to your next problem - the calculation for pennies. I assume that the value of penny is 1. What do you get when you do x % 1 for any integer value of x? You get 0. Knowing that after you count quarters, dimes and nickels, all that's left is pennies, right? So why not just take what's left as the count of pennies?

No guarantees there aren't other issues with your logic, especially after you make these fixes, but your question was why you weren't getting any output. ;-)

If this answers your question, please accept this answer to close the question. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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