How can I fix parser Error in ASP.NET?

In C++, I am having the same error problems that i can not seem to fix? Help please!?

  • I have put mark where the error is and what the error message is on the code The code: #include<iostream> #include<string> #include<fstream> #include<iomanip> #include<cstdlib> using namespace std; void calculateAvgerage( ifstream&, ofstream&, double& ); << First Error ^^^ The code above is the first error Error Message: error: in passing argument 1 of 'void calculateAvgerage(std::ifstream&, std::ofstream&, double&)'| char calculateGrade( double totalAvg ); int main( ) { char fileName[20]; double scoreAvg; double average = 0; int counter = 0; string name; ifstream inFile; ofstream outFile; //To read and store data cout<<"Enter input file name: "<<endl; cin>>fileName; inFile.open(fileName); if(!inFile) { cout<<"input file did not open please check it\n"<<endl; system("pause"); return 1; } cout<<"Enter output file name: "<<endl; cin>>fileName; outFile.open(fileName); outFile << fixed << showpoint << setprecision(2); outFile << "Student Test1 Test2 Test3 Test4 Test5 Average Grade"<< endl; while ( inFile.good() ) { inFile >> name; if ( !inFile ) break; outFile << setw( 10 ) << left << name; calculateAvgerage ( inFile, outFile, scoreAvg ); outFile << setw( 10 ) << right << scoreAvg; outFile << setw( 6 ) << right << calculateAvgerage(scoreAvg)<<endl; << Second Error ^^^^ The code above is the second error: Error Message: error: invalid initialization of reference of type 'std::ifstream&' from expression of type 'double'| counter++; average += scoreAvg; } // output the results average = average/counter; outFile << endl << "Class Average = " << average; inFile.close( ); outFile.close( ); system("pause"); return 0; } void calculateAvgerage( ifstream& input, ofstream& output, double& scoreavg ) { double scoreAvg=0; int score; for ( int i = 0; i < 5; i++ ) { input >> score; output << setw( 7 ) << right << score; scoreavg += score; } scoreAvg =scoreAvg/ 5.0; } char calculateGrade( double totalAvg ) { if ( totalAvg >=90 ) return 'A'; else if ( totalAvg >=80 ) return 'B'; else if ( totalAvg>=70 ) return 'C'; else if ( totalAvg >=60 ) return 'D'; else return 'F'; } ______________________ What am i doing wrong and how can i fix these errors?

  • Answer:

    1. I changed the prototype of your calculateAvgerage function to accomodate an additional optional parameter designating the fieldwidth for the test scores. 2. In function calculateAvgerage the following changes were applied: a) omit variable double scoreAvg in favour of using the scoreavg parameter; b) using the iFieldwidth parameter instead of the arbitrary value 7 3. In function main I broke down your title using iFieldwidth as width designator 4. Function calculateAvgerage. a) It is declared void. So you cannot use it together width cout. In case you would declare this function double, then you could leave your notation. However, you then would return a double and wouldn't need to pass the third parameter as a reference b) calculateAvgerage takes three (now four) parameters. In your function call you only used one. I hope that this helps! Cheers

MichaelInScarborough at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

1. I changed the prototype of your calculateAvgerage function to accomodate an additional optional parameter designating the fieldwidth for the test scores. 2. In function calculateAvgerage the following changes were applied: a) omit variable double scoreAvg in favour of using the scoreavg parameter; b) using the iFieldwidth parameter instead of the arbitrary value 7 3. In function main I broke down your title using iFieldwidth as width designator 4. Function calculateAvgerage. a) It is declared void. So you cannot use it together width cout. In case you would declare this function double, then you could leave your notation. However, you then would return a double and wouldn't need to pass the third parameter as a reference b) calculateAvgerage takes three (now four) parameters. In your function call you only used one. I hope that this helps! Cheers

MichaelI...

Try actually giving your parameters arbitrary names like this void calculateAvgerage( ifstream &input, ofstream &output, double & number ); double number should probably also be an array, but it's your choice on how to implement it. The second error comes from the fact you're not correctly calling your "calculate Avgerage function" (and you spelled average incorrectly) You should call it like this outFile << setw( 6 ) << right << calculateAvgerage(input,output,number)<<… << Second Error

include<iostream> #include<string> #include<fstream> #include<iomanip> #include<cstdlib> using namespace std; void calculateAverage ( ifstream* inFile, ofstream* outFile, double* scoreAvg ); char calculateGrade( double totalAvg ); int main( ) {  char fileName[20];  double scoreAvg;  double average = 0;  int counter = 0;  string name;  ifstream inFile;  ofstream outFile;  //To read and store data  cout<<"Enter input file name: "<<endl;  cin>>fileName;  inFile.open(fileName);  if(!inFile) {   cout<<"input file did not open please check it\n"<<endl;   system("pause");   return 1;  }  cout<<"Enter output file name: "<<endl;  cin>>fileName;  outFile.open(fileName);  outFile << fixed << showpoint << setprecision(2);  outFile << "Student Test1 Test2 Test3 Test4 Test5 Average Grade"<< endl;  while ( inFile.good() ) {   inFile >> name;   if ( !inFile )    break;   outFile << setw( 10 ) << left << name;   calculateAverage ( &inFile, &outFile, &scoreAvg );   outFile << setw( 10 ) << right << scoreAvg;   outFile << setw( 6 ) << right << calculateGrade(scoreAvg)<<endl;   counter++;   average += scoreAvg;  }  // output the results  average = average/counter;  outFile << endl << "Class Average = " << average;  inFile.close( );  outFile.close( );  system("pause");  return 0; } void calculateAverage ( ifstream* input, ofstream* output, double* scoreAvg ) {  double scoreavg=0;  int score;  for ( int i = 0; i < 5; i++ ) {   *input >> score;   *output << setw( 7 ) << right << score;   scoreavg += score;  }  *scoreAvg = scoreavg / 5.0; } char calculateGrade( double totalAvg ) {  if ( totalAvg >=90 )   return 'A';  else if ( totalAvg >=80 )   return 'B';  else if ( totalAvg>=70 )   return 'C';  else if ( totalAvg >=60 )   return 'D';  else   return 'F'; }

Thor

include<iostream> #include<string> #include<fstream> #include<iomanip> #include<cstdlib> using namespace std; void calculateAverage ( ifstream* inFile, ofstream* outFile, double* scoreAvg ); char calculateGrade( double totalAvg ); int main( ) { char fileName[20]; double scoreAvg; double average = 0; int counter = 0; string name; ifstream inFile; ofstream outFile; //To read and store data cout<<"Enter input file name: "<<endl; cin>>fileName; inFile.open(fileName); if(!inFile) { cout<<"input file did not open please check it\n"<<endl; system("pause"); return 1; } cout<<"Enter output file name: "<<endl; cin>>fileName; outFile.open(fileName); outFile << fixed << showpoint << setprecision(2); outFile << "Student Test1 Test2 Test3 Test4 Test5 Average Grade"<< endl; while ( inFile.good() ) { inFile >> name; if ( !inFile ) break; outFile << setw( 10 ) << left << name; calculateAverage ( &inFile, &outFile, &scoreAvg ); outFile << setw( 10 ) << right << scoreAvg; outFile << setw( 6 ) << right << calculateGrade(scoreAvg)<<endl; counter++; average += scoreAvg; } // output the results average = average/counter; outFile << endl << "Class Average = " << average; inFile.close( ); outFile.close( ); system("pause"); return 0; } void calculateAverage ( ifstream* input, ofstream* output, double* scoreAvg ) { double scoreavg=0; int score; for ( int i = 0; i < 5; i++ ) { *input >> score; *output << setw( 7 ) << right << score; scoreavg += score; } *scoreAvg = scoreavg / 5.0; } char calculateGrade( double totalAvg ) { if ( totalAvg >=90 ) return 'A'; else if ( totalAvg >=80 ) return 'B'; else if ( totalAvg>=70 ) return 'C'; else if ( totalAvg >=60 ) return 'D'; else return 'F'; }

Try actually giving your parameters arbitrary names like this void calculateAvgerage( ifstream &input, ofstream &output, double & number ); double number should probably also be an array, but it's your choice on how to implement it. The second error comes from the fact you're not correctly calling your "calculate Avgerage function" (and you spelled average incorrectly) You should call it like this outFile << setw( 6 ) << right << calculateAvgerage(input,output,number)<<... << Second Error

Igotreported

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.