Learn to Program Step-by-Step

Calculate change


This finds the change by first finding the number of dollars, then reducing the value of change by that amount.

It continues this way, for each coin, each time reducing the value of change by the amount of change that has been given.

For instance if change starts out as 57 cents, we give 0 dollars in change and change is still 57. Then we give 2 quarters and cahnge is now 7. We give one nickel and now change is 2, leaving one penny.