# Change Machine Problem

• 02-12-2012
dmarsden1
Change Machine Problem
In my introduction to computer programming course i was a given a project asking to create a change maker. Specifically, i must write a program that will make change in coins for any amount up to 99 cents using the fewest possible coins. The program should prompt the user to enter an amount, and then print out the number of each type of coin to make that amount of change. If there are no coins of a particular type, then the program should not print a line for that coin.

Examples:

Enter the change amount: 93
Quarters: 3
Dimes: 1
Nickels: 1
Pennies: 3

Enter the change amount: 89
Quarters: 3
Dimes: 1
Pennies: 4

This is what i have so far. The program works unless the "change" value falls under 25 so i'm assuming the problem involves the "if" statements. I have been stuck for a while and was hoping someone could provide some suggestions.

Code:

```#include <stdio.h> main () { int change; int coins; int remainder; printf ("Please enter an amount of change from 0-99.\n"); scanf ("%d", &change); if (change>=25) { coins = change/25; printf ("Quarters: %d\n", coins); remainder = change%25; } if (remainder>=10) { coins = remainder/10; printf ("Dimes: %d\n", coins); remainder = remainder%10; } if (remainder>=5) { coins = remainder/5; printf ("Nickles: %d\n", coins); remainder = remainder%5; } if (remainder>0) { printf ("Pennies: %d\n", remainder); } }```
• 02-12-2012
laserlight
Suppose change == 24. What is the value of remainder at the end of the main function?
• 02-13-2012
nonoob
'remainder' is never initialized if the original amount is < 25.