You're getting crazy numbers back for change because you're just working out how many quarters the change consists of, then how many dimes, etc. but you're not taking into account the fact that if you've already given back some of the change in quarters, you don't have to give the whole change back in dimes, etc.
Also, your code didn't compile as is, I had to remove the second "} /* end while loop */.
If you need two while loops, presumable one is so that the user can keep entering new input over and over, and the inner loop is so that the user can enter multiple items. You have inner loop done, so add the outer loop, with some condition:
Of course, the assignment wants you to keep track of how many quarters/dimes, etc. the "bank" has, so you'll need an array, or separate counters to keep track of that, and decrease them as you use the coins appropriately. Presumably you'll need to check when they reach zero, and output that the bank has ran out of change?Code:int done = 0; while (1) { /* ask how many items, if they enter 0, break out of the outer while */ while (numItems != 0) { /* the inner loop that asks the amount for each item and adds it to the total */ numItems--; } /* the code that computes the change */ /* the code that outputs the amount of change */ }



LinkBack URL
About LinkBacks


