Thursday, July 30, 2009

Please help with C++ I have two errors?

error C2064: term does not evaluate to a function taking 3 arguments





error C2447: '{' : missing function header (old-style formal list?)





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cmath%26gt;





using std::cout;


using std::cin;


using std::endl;


using std::setprecision;


using std::ios;


using std::setiosflags;








//function prototypes


void getTestScores(double, double, double);


void calcAverage (double, double, double);


void displayAverage (double);





int main()


{





double score1 = 0.0;


double score2 = 0.0;


double score3 = 0.0;


double calcAverage = 0.0;


double average = 0.0;


//get input items


getTestScores(score1, score2, score3);





//calculate average score


calcAverage (score1, score2, score3);


//display output item


displayAverage (average);





return 0;


} //end of main function





//*****program-defined functions*****


void getTestScores(double, double, double);





{


cout %26gt;%26gt;"Testscore:";


getline(cin, score);


cout %26lt;%26lt; "calcAverage: ";


cin %26gt;%26gt; average;


cout %26lt;%26lt; "displayAverage: ";


cin %26gt;%26gt; average;





} //end of getInput function

Please help with C++ I have two errors?
Looks like lots of things are wrong here. But the first error is that you declare a function calcAverage, then when Main roles around, you try to assign calcAverage a value as if it is a variable.
Reply:Ok.





First, I'm sure about the second error... If you check, when you're defining the function getTestScores, after the end of the main function, you are defining it in the wrong way:





void getTestScores(double, double, double);





This works only to declare the function, but not for defining it. You should include the names of the three variables and should NOT include a semicolon before the brace opening, change it to something like:





void getTestScores(double sc1, double sc2, double sc3)


{





etc.





About the first error, I think it happens because you have a local variable with the same name of the function, so, when the compiler finds the line





calcAverage(score1, score2, score3);





it resolves calcAverage as a double and not as a function.





You should change one of the names, the function name or the variable name.





Greetings,





Daniel.
Reply:The first error is probably because you've defined 'calcAverage' to be a double inside of main. Rename either the double or the function and that error should go away.





The second error is because you put a semicolon at the end of getTestScores in the function definition. Remember that error, because you'll see it a lot. It almost always means "oops, I put the semi in the function definition".





void Foo( int x ) //no semi here!


{


//do stuff


}





If you declare a function, then define it later, then you do put a semi.





void Foo(int x);


No comments:

Post a Comment