# Thread: Help with this program

1. ## Help with this program

Hello, I have a program I am trying to write. In my book it asks for me to make a program that takes pennies, dimes, nickles, half dollars, and quaters and make a total out of them. I have attempted to make the program. If anyone can point me in the right direction on fixing this, it would be great.

I have 20 quaters, 12 Half dollars, 32 dimes, 45 Nickels, 27 pennies. I

Heres my code:

Code:
```#include <stdio.h>
int main()
{
float quat;    /* declare quat as a double variable */
float halfdol; /* declare halfdol as a double variable */
float dime;    /* declare dime as a double variable */
float nick;    /* declare nick as a double variable */
float pen;     /* declare pen as a double variable */

quat = 20 * .25f;
halfdol = 12 * .50f;
dime = 32 * .10f;
nick = 45 * .05f;
pen = 27 * .01f;
total = quat + halfdol + dime + nick + pen;
printf("The total of the change is %f");

return 0;
}```
Thanks, I think I am totally off on this. I am not looking for someone to do this for me. I am just looking for help. Thanks.

2. Code:
`printf("The total of the change is %f");`
printf() expects a variable to be passed for each %* in the format string; in this case, for a %f, it's expecting a float or a double variable.
Code:
```float num = 3.14;
printf("PI = %f\n", num);```

Code:
`printf("The total of the change is %f");`

just do this:

Code:
`printf("The total of the change is %f", total);`

4. Code:
`total = quat + halfdol + dime + nick + pen;`
where exactly is 'total' coming from? you haven't declared it!

Code:
`float quat;    /* declare quat as a double variable */`
A double variable is different from a float variable. doubles have more digits (or equal digits, but if one of the mentioned data types has more digits, it will be the double).

6. Hello, OK I have gotten some help so far. I fixed her up to this:

Code:
```#include <stdio.h>
int main()
{
float quat = .25;
float halfdol = .50;
float dime = .10;
float nick = .05;
float pen = .01;
float total;

quat * 20, halfdol * 12, dime * 32, nick * 45, pen * 27;

total = quat + halfdol + dime + nick + pen;

printf("The dollar amount is %f\n")

return 0;
}```
I get an error at the return 0; line
I get this error when i try to compile:

"fig263B.c", line 17.5: 1506-277 (S) Syntax error: possible missing ';' or ','?

it looks right to me... I just want to take the money, multiply the given amount of change by the value of each of the change and get a total. im confused beyond this... Please help!

7. It's because you're missing the semi-colon at the end of the printf() call right above it.

8. ok, I fixed the error, but when I run the program, it just gives me 0.0000000 as an answer. Thanks for the help.

Somewheres I must have some thing put wrong somewhere. it wont do the math, so somthing isent working.

9. Code:
`printf("The dollar amount is %f\n")`
You have to tell printf() what to substitute for the %f. Look at dwk's and neo_phyte's posts.

10. Originally Posted by kdubbz
Hello, OK I have gotten some help so far. I fixed her up to this:

Code:
```#include <stdio.h>
int main()
{
float quat = .25;
float halfdol = .50;
float dime = .10;
float nick = .05;
float pen = .01;
float total;

quat * 20, halfdol * 12, dime * 32, nick * 45, pen * 27;

total = quat + halfdol + dime + nick + pen;

printf("The dollar amount is %f\n")

return 0;
}```
I get an error at the return 0; line
I get this error when i try to compile:

"fig263B.c", line 17.5: 1506-277 (S) Syntax error: possible missing ';' or ','?

it looks right to me... I just want to take the money, multiply the given amount of change by the value of each of the change and get a total. im confused beyond this... Please help!
Ok, you've fixed the printf statement so it includes a semi-colon at the end. Now are you printing total, in that line of code?

And if you're printing total (pennies), what about then changing that total pennies to customary terms for money?

We don't say "I have 552 pennies", we say "I have 5 dollars and 52 cents". Something to work on there. For the sake of clarity, it might be nice to include an integer variable "dollars", if your assignment allows it.

11. > printf("The dollar amount is %f\n")
Pass a parameter, say
printf("The dollar amount is %f\n", total);

12. See post 2 and 3 in this thread. If you had read them you wouldn't be having that issue.

13. Ok, I fixed it up and its all done. Hey im getting good at this, this is my 2nd one done so far. hers the final code:

Code:
```#include <stdio.h>
int main()
{
float quat;
float halfdol;
float dime;
float nick;
float pen;
float total;

quat = .25;
halfdol = .5;
dime = .10;
nick = .05;
pen = .01;

total =  quat * 20 +  halfdol * 12 +  dime * 32 +  nick * 45 +  pen * 27;

printf("The dollar amount is %f\n",total);

return 0;
}```
Which gives you after compiling: The dollar amount is 16.719999

Success. Thanks guys.

14. Perhaps I dweal in an alternate universe. . . or am way behind the times. . . but would someone explain what the following line of code does?
Code:
`quat * 20, halfdol * 12, dime * 32, nick * 45, pen * 27;`
I think the answer to my question is NOTHING!!!

EDIT: Ah, kdubbz took that out just before I posted. . .