# coin problem

• 07-13-2008
et1wilson
coin problem
I am trying to do a coin problem but I can't seem to get it to work. When I complie it, there are no errors and the program lets me enter a number and then does nothing. I can't figure out what I did wrong and if anyone can point me in the right direction it would be very appricaited.
Code:

```#include <stdio.h> int main()     {             int total=0;             int quart=0;             int dime=0;             int nick=0;             int pen=0;                             {                         printf ("\n Enter the total (in cents): ");                         scanf(" %d, &total");                         quart = total/25;                         total = total - (quart * 25);                         dime = total/10;                         total = total - (dime * 10);                         nick = total/5;                         total = total - (nick * 5);                         pen = total;                         scanf("\n The change is:"  );                         if(quart != 0)                                 printf("\n %d qaurters ", quart );                         if(dime != 0)                                 printf("\n %d  dimes.", dime);                         if(nick != 0)                                 printf("\n %d nickels", nick);                         if(pen != 0)                                 printf("\n %d pennies ", pen);                      }         return 0;         }```
• 07-13-2008
MacGyver
Code:

`scanf("\n The change is:"  );`
Print the message, not try to read it.
• 07-13-2008
Quote:

Originally Posted by et1wilson
I am trying to do a coin problem but I can't seem to get it to work. When I complie it, there are no errors and the program lets me enter a number and then does nothing. I can't figure out what I did wrong and if anyone can point me in the right direction it would be very appricaited.
Code:

```#include <stdio.h> int main()     {             int total=0;             int quart=0;             int dime=0;             int nick=0;             int pen=0;                             {                         printf ("\n Enter the total (in cents): ");                         scanf(" &#37;d, &total");                         quart = total/25;                         total = total - (quart * 25);                         dime = total/10;                         total = total - (dime * 10);                         nick = total/5;                         total = total - (nick * 5);                         pen = total;                         scanf("\n The change is:"  );                         if(quart != 0)                                 printf("\n %d qaurters ", quart );                         if(dime != 0)                                 printf("\n %d  dimes.", dime);                         if(nick != 0)                                 printf("\n %d nickels", nick);                         if(pen != 0)                                 printf("\n %d pennies ", pen);                      }         return 0;         }```

1) I don't understand the braces I've marked in red, above.

2) After getting the cents, you would normally want a while loop for each type of coin:
Code:

```while(total >= 25)  {     quarters++;     total -= 25; }```
Repeat the above for each type of coin. There is no need for multiplication or division, just addition of the type of coin, and subtraction from the total.

Ez smeezy! :) << and *how* are you spelling quarters?? >> :p
• 07-13-2008
et1wilson
new problem
Ok I now have fixed it and chnaged a few things and get it to display the information but it is all 0.00000. What can I do to fix it?
Code:

``` #include <stdio.h> int main()     {             int total=0;             int quart=0;             int dime=0;             int nick=0;             int pen=0;                             {                         printf ("\n Enter the total (in cents): ");                         scanf(" %d, &total");                                                                  printf("\n The change is:"  );                         if(quart != 0)                                 quart = total/25;                                 total = total - (quart * 25);                                 printf("\n %f qaurters ", quart );                         if(dime != 0)                                 dime = total/10;                                 total = total - (dime * 10);                                 printf("\n %f  dimes.", dime);                         if(nick != 0)                                 nick = total/5;                                 total = total - (nick * 5);                                 printf("\n %f nickels", nick);                         if(pen != 0)                         pen = total;                                 printf("\n %f pennies ", pen);                      }         return 0;         }```
• 07-13-2008
MacGyver
Print the values as ints.
• 07-14-2008
hk_mp5kpdw
Code:

`scanf(" &#37;d, &total");`
That a typo? Maybe it should be:
Code:

`scanf(" %d", &total);`