# Coin Counting Program

• 03-14-2011
woodyhavoc
Coin Counting Program
First I want to say that this is a homework assignment I am working on. However, I do not wish anyone to complete the entire assignment for me. I am just confused on some error messages that I am receiving with my code. I would greatly appreciate any advice on how to simply correct the error messages. Here is the code.

Code:

``` /* Assignment 6 Aaron Woods */ #include <stdio.h> #define CALL1 1.88 #define CALL2 0.32 int main () {     void change(double, int, int, int, int);     int quarters, dimes, nickels, pennies;     double value;     change();     printf("TOTAL VALUE ENTERED %f", value);     printf("%d quarters", quarters);     printf("%d dimes", dimes);     printf("%d nickels", nickels);     printf("%d pennies", pennies);     return 0; } void change() {     static int num;     double value;     int quarters, dimes, nickels, pennies, count, i;     if (num = 0)     {         value = CALL1;         while (value >= .25)         {             quarters++;             value = value - 0.25;         }         while (value >= 0.1)         {             dimes++;             value = value - 0.1;         }         while (value >= 0.05)         {             nickels++;             value = value - 0.05;         }         while (value >= 0.01)         {             pennies++;             value = value - 0.01;         }         num++;     }     else if (num = 1)     {         value = CALL2;         while (value >= .25)         {             quarters++;             value = value - 0.25;         }         while (value >= 0.1)         {             dimes++;             value = value - 0.1;         }         while (value >= 0.05)         {             nickels++;             value = value - 0.05;         }         while (value >= 0.01)         {             pennies++;             value = value - 0.01;         }         num++;     }     else if (num = 2)     {         printf("Please enter the amount of money\n");         printf("you would like a breakdown of coins for: ");         scanf("%f", &value);         while (value >= .25)         {             quarters++;             value = value - 0.25;         }         while (value >= 0.1)         {             dimes++;             value = value - 0.1;         }         while (value >= 0.05)         {             nickels++;             value = value - 0.05;         }         while (value >= 0.01)         {             pennies++;             value = value - 0.01;         }         num++;     } }```
Here are the error messages I am receiving.

Code:

```C:\Users\Aaron Woods\Documents\School Work\C Programming\Assignment 6\Assignment 6.c||In function 'main':| C:\Users\Aaron Woods\Documents\School Work\C Programming\Assignment 6\Assignment 6.c|16|error: too few arguments to function 'change'| C:\Users\Aaron Woods\Documents\School Work\C Programming\Assignment 6\Assignment 6.c||In function 'change':| C:\Users\Aaron Woods\Documents\School Work\C Programming\Assignment 6\Assignment 6.c|29|error: number of arguments doesn't match prototype| C:\Users\Aaron Woods\Documents\School Work\C Programming\Assignment 6\Assignment 6.c|12|error: prototype declaration| ||=== Build finished: 3 errors, 0 warnings ===|```
I apologize for the length. Again I would greatly appreciate any assistance. I am very amateur with C. I am in my first class for it in college.

Thanks

Aaron
• 03-14-2011
Phenax
Code:

`void change(double, int, int, int, int);`
Is different than the actual declaration of your function
Code:

`void change()`
• 03-14-2011
woodyhavoc
I'm trying to call change() three times. The first time to determine the coin breakdown of \$1.88, the second \$0.32, and the third as a user specified amount.

I think what you are explaining to me might be just a bit more advanced than what I have covered so far in the course.
• 03-14-2011
Phenax
Quote:

Originally Posted by woodyhavoc
I'm trying to call change() three times. The first time to determine the coin breakdown of \$1.88, the second \$0.32, and the third as a user specified amount.

I think what you are explaining to me might be just a bit more advanced than what I have covered so far in the course.

Yeah, sorry, I misinterpreted your question.

Code:

`if (num = 0)`
== tests for equality. Using = is different then ==. Your current if statement does this: Sets num to zero. This operation returns 0 and thus your if statement does not execute.

Also, you don't set your "num" variable anywhere, you probably want to initialize it to zero.
You can't correctly print those variables from main (quarters, dimes, etc), you're just going to get random uninitialized variables. Setting a variable equal to something in another function does not mean a variable with a same name in a different function will have the same value. This is called the scope of a variable, and most variables you declare in a function have a scope of that function.
• 03-14-2011
declare your coins in main: pennies, nickels, dimes, quarters, etc.

Then send them, via their address, to your various functions, as you wish. Otherwise, if you declare them locally (not in main), then their values will be lost when your program returns from the function that the coins were declared in.

You may call your functions as many times as you want. You may want to zero out the value of the coins, from the last call, before you call them again.
• 03-14-2011
woodyhavoc
I initialized 'num' in my change() function as:

Code:

`static int num;`
This should set num equal to zero, at least that is what I understand from what I read in my book. I moved it up to my main function though.
• 03-14-2011
Phenax
Quote:

Originally Posted by woodyhavoc
I initialized 'num' in my change() function as:

Code:

`static int num;`
This should set num equal to zero, at least that is what I understand from what I read in my book. I moved it up to my main function though.

My mistake, statics are indeed initialized to 0 by default. But I think it'd be better to explicitly initialize it to 0 to be clear about your intentions.
• 03-14-2011
woodyhavoc
Yeah, that is a good idea. I would probably forget what I was trying to do if I don't explicitly define it.
• 03-14-2011
```#include <stdio.h> /* the actual names of the variables is not needed here, just the type */ void change(int *pennies, int *nickels, int *dimes, int *quarters); //function prototype int main(void) {   int pennies, nickels, dimes, quarters;   change(&pennies, &nickels, &dimes, &quarters);   /* your other code here to print up the change */   return 0; } void change(int *pennies, int *nickels, int *dimes, int *quarters) {   //do not declare these variables again - they're already "here".   /* do your calculations in here */ }```