# i keep getting this error :: error C2664: 'calcTotal' : cannot convert parameter 5 from 'int' to 'double &'

### Question

• /* Author:  Unique Perry
Date:    10/11/2013
Purpose: Calculate the amount of money in a piggy bank.
*/

//preprocessor directives
#include <iostream>
#include <string>

//namespace statement
using namespace std;

//function prototypes
void getNum(int& numpennie, int& numnickel, int& numdime, int& numquarter);
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total);
void printTotal(double total);

//main function
int main(){
//Declare int variables numpennie, numnickel, numdime, numquarter, total
int numpennie, numnickel, numdime, numquarter, total;
//function call:  getNum
getNum(numpennie, numnickel, numdime, numquarter);
//function call:  calcTotal
calcTotal(numpennie, numnickel, numdime, numquarter, total);
//function call:  printTotal
printTotal(total);
//Print "Press any key to continue..." and wait for a key press
system ("pause");
//end the main function
return 0;
}

//getNum function: Gets the number of pennies, nickles, dimes, and quarters from the user
void getNum(int numpennie, int numnickel, int numdime, int numquarter){
//Prompt the user to " Enter the number of pennies:"
cout << " Enter the number of pennies: ";
//Get user input and store in numpennie
cin >> numpennie;
//Prompt the user to "Enter the number of nickles: "
cout << " Enter the number of nickles: ";
//Get the user input and store in numnickel
cin >> numnickel;
//Prompt the user to "Enter the number of dimes: "
cout << " Enter the number of dimes: ";
//Get the user input and store in numdime
cin >> numdime;
//Prompt the user to "Enter the number of quarters: "
cout << " Enter the number of quarters ";
//Get the user input and store in numquarter
cin >> numquarter;
}

//calcTotal function: Calcualtes the total amount of money
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total){
//Calculate the amount the coins and store it in total
total = numpennie * 0.1 + numnickel * 0.5 + numdime * 0.10 +  numquarter * 0.25;
}

//printTotal function: Prints the total amount of money
void printTotal(double total){
//Print "The total is: "
cout << " The total is: ";
//Print the total on the screen
cout << total;
Thursday, October 17, 2013 7:07 AM

• THE FUNCTION SHOULD PRINT "YOU SHOULD SAVE MORE!" IF THE AMOUNT IS LESS THAN \$25.00, AND SHOULD PRINT "YOU'RE DOING GREAT!" IF THE AMOUNT IS OVER \$25.00

What if it's exactly \$25.00, not less than and not over?

>IDK HOW TO DO THAT ?

Use a conditional statement:

if Statement (C)
http://msdn.microsoft.com/en-us/library/fh88ctk1%28v=vs.100%29.aspx

Lesson 2: If statements in C++
http://www.cprogramming.com/tutorial/lesson2.html

- Wayne

Thursday, October 17, 2013 10:46 PM
• IT TELLS ME MY VARIABLES ARE BEING USED WITHOUT BEING INITIALIZED ????

You need to learn the difference between pass by value and pass by reference.

When you pass by value:

getNum(numpennie, numnickel, numdime, numquarter);

What gets altered inside that function are temporary copies of the variables,
not the variables being passed to the function. So the variables in main()
are not being set to any values.

- Wayne

Thursday, October 17, 2013 9:23 PM
• I DONT EVEN UNDERSTAND WHAT YOUR SAYING HONESTLY THIS IS MY FIRST SEMESTER IN THIS COURSE SMH ,.

Correction to my last post (now deleted).

Change:

void getNum(int numpennie, int numnickel, int numdime, int numquarter);

to

void getNum(int &numpennie, int &numnickel, int &numdime, int &numquarter)

- Wayne

Thursday, October 17, 2013 9:37 PM
• //printTotal function: Prints the total amount of money
void printTotal(double total){
//Print "The total is: "
cout << " The total is: ";
//Print the total on the screen
cout << total;
}

the amount has to be in dollars though but is this still correct ?

To get a more readable total, change this:

cout << total;

to this:

cout << fixed << setprecision(2) << total << endl; // #include <iomanip>

- Wayne

Thursday, October 17, 2013 10:24 PM

### All replies

• What's confusing about that? You have defined the function to take a reference to a double
as the fifth argument and you are calling it passing an int to the fifth argument. Make
them match.

- Wayne
Thursday, October 17, 2013 8:03 AM
• You might want to take another very careful look at the calcTotal function.

When you have printed the last text on a line, it is a good idea to terminate the print with either endl or '\n'.

And PLEASE forgo the use of comments that do nothing but repeat what is already in the code.

Thursday, October 17, 2013 12:15 PM
• smh im still getting the same error i changed my variable in my get data function to regular paramerts and not references
Thursday, October 17, 2013 7:09 PM
• im still getting the same errors
Thursday, October 17, 2013 7:10 PM
• im still getting the same errors

Then show your code with the latest changes.
Thursday, October 17, 2013 7:23 PM
• #include <iostream>
#include <string>

//namespace statement
using namespace std;

//function prototypes
void getNum(int numpennie, int numnickel, int numdime, int numquarter);
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total);
void printTotal(double total);

//main function
int main(){
//Declare int variables numpennie, numnickel, numdime, numquarter
int numpennie, numnickel, numdime, numquarter;
//Declare double variables
double total
//function call:  getNum
getNum(numpennie, numnickel, numdime, numquarter);
//function call:  calcTotal
calcTotal(numpennie, numnickel, numdime, numquarter, total);
//function call:  printTotal
printTotal(total);
//Print "Press any key to continue..." and wait for a key press
system ("pause");
//end the main function
return 0;
}

//getNum function: Gets the number of pennies, nickles, dimes, and quarters from the user
void getNum(int numpennie, int numnickel, int numdime, int numquarter){
//Prompt the user to " Enter the number of pennies:"
cout << " Enter the number of pennies: ";
//Get user input and store in numpennie
cin >> numpennie;
//Prompt the user to "Enter the number of nickles: "
cout << " Enter the number of nickles: ";
//Get the user input and store in numnickel
cin >> numnickel;
//Prompt the user to "Enter the number of dimes: "
cout << " Enter the number of dimes: ";
//Get the user input and store in numdime
cin >> numdime;
//Prompt the user to "Enter the number of quarters: "
cout << " Enter the number of quarters ";
//Get the user input and store in numquarter
cin >> numquarter;
}

//calcTotal function: Calcualtes the total amount of money
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total){
//Calculate the amount the coins and store it in total
total = numpennie * 0.1 + numnickel * 0.5 + numdime * 0.10 +  numquarter * 0.25;
}

//printTotal function: Prints the total amount of money
void printTotal(double total){
//Print "The total is: "
cout << " The total is: ";
//Print the total on the screen
cout << total <<endl;
}

the only error im getting now is: error C2146: syntax error : missing ';' before identifier 'getNum'

Thursday, October 17, 2013 8:10 PM
• #include <iostream>
#include <string>

//namespace statement
using namespace std;

//function prototypes
void getNum(int numpennie, int numnickel, int numdime, int numquarter);
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total);
void printTotal(double total);

//main function
int main(){
//Declare int variables numpennie, numnickel, numdime, numquarter
int numpennie, numnickel, numdime, numquarter;
//Declare double variables
double total
//function call:  getNum
getNum(numpennie, numnickel, numdime, numquarter);

...

the only error im getting now is: error C2146: syntax error : missing ';' before identifier 'getNum'

Isn't that rather evident and self-explanatory? You now have this line:

double total

What's missing?

- Wayne

Thursday, October 17, 2013 9:02 PM
• the only error im getting now is: error C2146: syntax error : missing ';' before identifier 'getNum'

That is because you left out a ; before getNum(!)

Thursday, October 17, 2013 9:03 PM
• /* Author:  Unique Perry
Date:    10/11/2013
Purpose: Calculate the amount of money in a piggy bank.
*/

//preprocessor directives
#include <iostream>
#include <string>

//namespace statement
using namespace std;

//function prototypes
void getNum(int numpennie, int numnickel, int numdime, int numquarter);
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total);
void printTotal(double total);

//main function
int main(){
//Declare int variables numpennie, numnickel, numdime, and numquarter
int numpennie, numnickel, numdime, numquarter;
//Declare double variables total
double total;
//function call:  getNum
getNum(numpennie, numnickel, numdime, numquarter);
//function call:  calcTotal
calcTotal(numpennie, numnickel, numdime, numquarter, total);
//function call:  printTotal
printTotal(total);
//Print "Press any key to continue..."
//and wait for a key press
system ("pause");
//end the main function
return 0;
}

//getNum function: Gets the number of pennies, nickles, dimes, and quarters from the user
void getNum(int numpennie, int numnickel, int numdime, int numquarter){
//Prompt the user to " Enter the number of pennies:"
cout << " Enter the number of pennies: ";
//Get user input and store in numpennie
cin >> numpennie;
//Prompt the user to "Enter the number of nickles: "
cout << " Enter the number of nickles: ";
//Get the user input and store in numnickel
cin >> numnickel;
//Prompt the user to "Enter the number of dimes: "
cout << " Enter the number of dimes: ";
//Get the user input and store in numdime
cin >> numdime;
//Prompt the user to "Enter the number of quarters: "
cout << " Enter the number of quarters: ";
//Get the user input and store in numquarter
cin >> numquarter;
}

//calcTotal function: Calcualtes the total amount of money
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total){
//Calculate the amount of the coins
//and store it in total
total = ( numpennie * .1 ) + ( numnickel * .5 ) + ( numdime * .10 ) + ( numquarter * .25 );
}

//printTotal function: Prints the total amount of money
void printTotal(double total){
//Print "The total is: "
cout << " The total is: ";
//Print the total on the screen
cout << total;
}

THIS IS THE FINAL PROGRAM IT RUNS BUT THE TOTAL COMES OUT WRONG AND I GET THE ERROR :The variable 'numnickel' is being used without being initialized. BUT I GET THAT ERROR FOR ALL 4 VARIABLES

Thursday, October 17, 2013 9:07 PM
• THANKS I FIXED THAT IT RUNS BUT THE TOTAL COMES OUT WRONG AND IT TELLS ME MY VARIABLES ARE BEING USED WITHOUT BEING INITIALIZED ????
Thursday, October 17, 2013 9:08 PM
• total = ( numpennie * .1 ) + ( numnickel * .5 ) + ( numdime * .10 ) + ( numquarter * .25 );

...

THIS IS THE FINAL PROGRAM IT RUNS BUT THE TOTAL COMES OUT WRONG AND I GET THE ERROR :The variable 'numnickel' is being used without being initialized. BUT I GET THAT ERROR FOR ALL 4 VARIABLES

What is the difference between multiplying by .1 or .10 or .100?

Do you think that a penny and a dime have the same value?

Do you really think that a nickel is worth more than a dime?

(I could simply correct your code, but it's better if you do it yourself.)

- Wayne

Thursday, October 17, 2013 9:17 PM
• IT TELLS ME MY VARIABLES ARE BEING USED WITHOUT BEING INITIALIZED ????

You need to learn the difference between pass by value and pass by reference.

When you pass by value:

getNum(numpennie, numnickel, numdime, numquarter);

What gets altered inside that function are temporary copies of the variables,
not the variables being passed to the function. So the variables in main()
are not being set to any values.

- Wayne

Thursday, October 17, 2013 9:23 PM
• NO BUT I FIGURED IN REGULAR MATH THATS THE EQUATION ON HOW TO CALCUALTE THE TOTAL AMOUNT OF MONEY ?
Thursday, October 17, 2013 9:30 PM
• I DONT EVEN UNDERSTAND WHAT YOUR SAYING HONESTLY THIS IS MY FIRST SEMESTER IN THIS COURSE SMH ,.
Thursday, October 17, 2013 9:31 PM
• AND I GOT "NUMVARIABLES" TO ENTER THE NUMBER OF THAT COIN AND MUTILPLY IT BY THE VALUE OF THE COIN TO GET THE AMOUNT OF THAT COIN AVAIABLE, SMH IM ALL CONFUSED AND IRRITATED
Thursday, October 17, 2013 9:33 PM
• I DONT EVEN UNDERSTAND WHAT YOUR SAYING HONESTLY THIS IS MY FIRST SEMESTER IN THIS COURSE SMH ,.

Correction to my last post (now deleted).

Change:

void getNum(int numpennie, int numnickel, int numdime, int numquarter);

to

void getNum(int &numpennie, int &numnickel, int &numdime, int &numquarter)

- Wayne

Thursday, October 17, 2013 9:37 PM
• NO BUT I FIGURED IN REGULAR MATH THATS THE EQUATION ON HOW TO CALCUALTE THE TOTAL AMOUNT OF MONEY ?

You can never write valid code to do math if you don't understand the math itself.

Bring up Windows' Calculator.

Try:

2 * .1 =

2 * .100 =

2 * .1000 =

Are they the same or different?

Try:

2 * .5 =

Is that what a nickel is worth?

How about a fifty cent piece then?

Now try:

2 * .05 =

Does that look any better?

Which coin has the value of .01 ?

- Wayne

• Edited by Thursday, October 17, 2013 9:45 PM
Thursday, October 17, 2013 9:44 PM
• OOOOOOOOOO
Thursday, October 17, 2013 9:47 PM
• I THOUGHT THEY ONLY REFERENCES IF THEY HAVE TO RETURN BACK TO MAIN THOUGH ?
Thursday, October 17, 2013 9:48 PM
• I CHANGED ALL MY VALUES TO THE CORRECT VALUE AND I STILL GET THIS ERROR : Run-Time Check Failure #3 - The variable 'numdime' is being used without being initialized. BUT FOR ALL OF THE VARIABLES STILL
Thursday, October 17, 2013 9:54 PM
• SMH IT STILL DOESNT RUN RIGHT
Thursday, October 17, 2013 9:55 PM
• I CHANGED ALL MY VALUES TO THE CORRECT VALUE AND I STILL GET THIS ERROR : Run-Time Check Failure #3 - The variable 'numdime' is being used without being initialized. BUT FOR ALL OF THE VARIABLES STILL

Did you make the change I told you to make, so that you are passing references to getNum?

- Wayne

Thursday, October 17, 2013 10:01 PM
• /* Author:  Unique Perry
Date:    10/11/2013
Purpose: Calculate the amount of money in a piggy bank.
*/

//preprocessor directives
#include <iostream>
#include <string>

//namespace statement
using namespace std;

//function prototypes
void getNum(int& numpennie, int& numnickel, int& numdime, int& numquarter);
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total);
void printTotal(double total);

//main function
int main(){
//Declare int variables numpennie, numnickel, numdime, and numquarter
int numpennie, numnickel, numdime, numquarter;
//Declare double variables total
double total;
//function call:  getNum
getNum(numpennie, numnickel, numdime, numquarter);
//function call:  calcTotal
calcTotal(numpennie, numnickel, numdime, numquarter, total);
//function call:  printTotal
printTotal(total);
//Print "Press any key to continue..."
//and wait for a key press
system ("pause");
//end the main function
return 0;
}

//getNum function: Gets the number of pennies, nickles, dimes, and quarters from the user
void getNum(int& numpennie, int& numnickel, int& numdime, int& numquarter){
//Prompt the user to " Enter the number of pennies:"
cout << " Enter the number of pennies: ";
//Get user input and store in numpennie
cin >> numpennie;
//Prompt the user to "Enter the number of nickles: "
cout << " Enter the number of nickles: ";
//Get the user input and store in numnickel
cin >> numnickel;
//Prompt the user to "Enter the number of dimes: "
cout << " Enter the number of dimes: ";
//Get the user input and store in numdime
cin >> numdime;
//Prompt the user to "Enter the number of quarters: "
cout << " Enter the number of quarters: ";
//Get the user input and store in numquarter
cin >> numquarter;
}

//calcTotal function: Calcualtes the total amount of money
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total){
//Calculate the amount of the coins
//and store it in total
total = ( numpennie * .01 ) + ( numnickel * .05 ) + ( numdime * .10 ) + ( numquarter * .25 );
}

//printTotal function: Prints the total amount of money
void printTotal(double total){
//Print "The total is: "
cout << " The total is: ";
//Print the total on the screen
cout << total;
}

the amount has to be in dollars though but is this still correct ? and when i add my printGreeting function wouldnt it just go before my getNum function ?

Thursday, October 17, 2013 10:14 PM
• //printTotal function: Prints the total amount of money
void printTotal(double total){
//Print "The total is: "
cout << " The total is: ";
//Print the total on the screen
cout << total;
}

the amount has to be in dollars though but is this still correct ?

To get a more readable total, change this:

cout << total;

to this:

cout << fixed << setprecision(2) << total << endl; // #include <iomanip>

- Wayne

Thursday, October 17, 2013 10:24 PM
• mr wayne you have been a big help this is my final function but i have one last step lol

/* Author:  Unique Perry
Date:    10/11/2013
Purpose: Calculate the amount of money in a piggy bank.
*/

//preprocessor directives
#include <iostream>
#include <string>

//namespace statement
using namespace std;

//function prototypes
void printGreeting();
void getNum(int& numpennie, int& numnickel, int& numdime, int& numquarter);
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total);
void printTotal(double total);

//main function
int main(){
//Declare int variables numpennie, numnickel, numdime, and numquarter
int numpennie, numnickel, numdime, numquarter;
//Declare double variables total
double total;
//function call: printGreeting
printGreeting();
//function call:  getNum
getNum(numpennie, numnickel, numdime, numquarter);
//function call:  calcTotal
calcTotal(numpennie, numnickel, numdime, numquarter, total);
//function call:  printTotal
printTotal(total);
//Print "Press any key to continue..."
//and wait for a key press
system ("pause");
//end the main function
return 0;
}

//printGreeting function: Prints a message about what the program will do
void printGreeting(){
//This program will calculate the amount of money in a piggy bank, in dollars, by collecting the amount of coins in the bank and calculating the total amount
cout << " This program will calculate the amount of money in a piggy bank, in dollars, by collecting the amount of coins in the bank and calculating the total amount ";
//Print a line break
cout << endl;
}

//getNum function: Gets the number of pennies, nickles, dimes, and quarters from the user
void getNum(int& numpennie, int& numnickel, int& numdime, int& numquarter){
//Prompt the user to " Enter the number of pennies:"
cout << " Enter the number of pennies: ";
//Get user input and store in numpennie
cin >> numpennie;
//Prompt the user to "Enter the number of nickles: "
cout << " Enter the number of nickles: ";
//Get the user input and store in numnickel
cin >> numnickel;
//Prompt the user to "Enter the number of dimes: "
cout << " Enter the number of dimes: ";
//Get the user input and store in numdime
cin >> numdime;
//Prompt the user to "Enter the number of quarters: "
cout << " Enter the number of quarters: ";
//Get the user input and store in numquarter
cin >> numquarter;
}

//calcTotal function: Calcualtes the total amount of money
void calcTotal(int numpennie, int numnickel, int numdime, int numquarter, double& total){
//Calculate the amount of the coins
//and store it in total
total = ( numpennie * .01 ) + ( numnickel * .05 ) + ( numdime * .10 ) + ( numquarter * .25 );
}

//printTotal function: Prints the total amount of money
void printTotal(double total){
//Print "The total is: "
cout << " The total is: ";
//Print the total on the screen
cout << total;
//Print a line break
cout << endl;
}

THE FUNCTION SHOULD PRINT "YOU SHOULD SAVE MORE!" IF THE AMOUNT IS LESS THAN \$25.00, AND SHOULD PRINT "YOU'RE DOING GREAT!" IF THE AMOUNT IS OVER \$25.00

IDK HOW TO DO THAT ?

Thursday, October 17, 2013 10:30 PM
• THE FUNCTION SHOULD PRINT "YOU SHOULD SAVE MORE!" IF THE AMOUNT IS LESS THAN \$25.00, AND SHOULD PRINT "YOU'RE DOING GREAT!" IF THE AMOUNT IS OVER \$25.00

What if it's exactly \$25.00, not less than and not over?

>IDK HOW TO DO THAT ?

Use a conditional statement:

if Statement (C)
http://msdn.microsoft.com/en-us/library/fh88ctk1%28v=vs.100%29.aspx

Lesson 2: If statements in C++
http://www.cprogramming.com/tutorial/lesson2.html

- Wayne

Thursday, October 17, 2013 10:46 PM
• NO ON THE INTRUCTIONS IT SAYS ONLY THAT NO IF IT'S EXACTLY 25.00
Thursday, October 17, 2013 10:49 PM
• SO IT GOES IN THE MAIN FUNCTION ?

Thursday, October 17, 2013 10:51 PM
• SO IT GOES IN THE MAIN FUNCTION ?

It goes wherever you want it to go.

- Wayne

Thursday, October 17, 2013 10:53 PM
• THIS IS WHAT I HAVE...

//IF TOTAL IS LESS THAN 25.00

IF (TOTAL < 25.00){

//PRINT "YOU SHOULD SAVE MORE!"

COUT << " YOU SHOULD SAVE MORE ! ";

} ELSE {

//PRINT "YOU'RE DOING GREAT!"

COUT << " YOU'RE DOING GREAT !;

Thursday, October 17, 2013 11:00 PM
• nevermind it works thank you very much !
Thursday, October 17, 2013 11:10 PM