In C++, what does this error mean and how do you fix it part 3 (code include)?
-
The Code: Please ignore the comments #include <iostream> // Provides input and output fundamentals #include <cstdlib>// Allows the code: system("pause") to be use in this program #include <fstream> /* library containing input and output functions to read to or from a file*/ #include <iomanip>/* This will allow you to the code called setprecision(n) in in the program*/ #include <string>/* Allow you to directly initialize, assign, compare, and reassign with the intuitive operators, as well as printing and reading*/ using namespace std; /* allow the user to group entities like classes, objects and functions under a name ithout the prefix std:*/ /* The code below states an void function named calculateAverage which is given the formal parameter list named ifstream&, ofstream&, and double& */ void calculateAverage ( ifstream&, ofstream&, double& ); /* The code below states an return value function type char named calculateGrade with the parameter list named double totalAvg */ char calculateGrade (double totalAvg); int main() {// Start of function main string name;// States an string variable named name double scoreAvg;// States an double variable named scoreAvg which is given no value double average=0;//States an double variable named average which is given the value of 0 int counter=0;// States an int variable named counter which is given the value of 0 ifstream inFile;// States an ifstream variable named inFile ofstream outFile;// States an ofstream variable named outFile inFile.open("courseScoreData.txt");/* Opens the data from the the file named courseScoreData and outputs the values*/ outFile.open("courseScoreResults.txt")... Opens the file named courseScoreResults and stores the values into it */ if (inFile.fail()) // if inFile fails to open it should output the following statement {// Start of if statement //The code below outputs the statement to let the user know that the infile fail to open and must be check cout<<"INPUT FAIL TO OPEN, PLEASE CHECK IT"<<endl; system("pause");// pause the system until you press enter return 1;// }// End of if statement outFile<< fixed; outFile.precision(2); /* The code below output the following statement: Student TestOne TestTwo TestThree TestFour TestFive Average Grade */ outFile<<"Student TestOne TestTwo TestThree TestFour TestFive Average Grade"<<endl; while ( true ) {// Start of while loop inFile >> name; if ( !inFile ) break; outFile << setw( 10 ) << left << name; calculateAverage ( inFile&, outFile&, double&); << The Problem outFile << setw( 10 ) << right << scoreAvg; outFile << setw( 6 ) << right << 'calculateGrade( scoreAvg)'<<endl; counter++; average += scoreAvg; }// End of While loop //Outputs Results average = average/counter; outFile << endl << "Class Average = " << average; inFile.close( ); outFile.close( ); system("pause");// Pause the system until you press enter return 0;// Ends the program }// End of function main //A function to calculate the average test score void testScoreAverage( ifstream& input, ofstream& output, double& scoreavg ) { scoreavg=0; int score; for ( int i = 0; i < 5; i++ ) { input >> score; output << setw( 7 ) << right << score; scoreavg += score; } scoreavg =scoreavg/ 5.0; } //A Returning Value Function to calculate the test score grade char testScoreGrade( 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'; } ______________________________________... Error Message: undefined reference to `calculateAverage(std::basic_ifstream<ch... std::char_traits<char> >&, std::basic_ofstream<char, std::char_traits<char> >&, double&)'| Hope someone can help
-
Answer:
Your problem is the function call calculateAverage ( inFile&, outFile&, double&); the function expects a reference to an ifstream, a reference to an ofstream, and a reference to a double. Not literally '<ifstream>&' your function call should look something like calculateAverage ( inFile, outFile, scoreAvg); instead (replace scoreAvg with whatever variable you actually need to use)
PC at Yahoo! Answers Visit the source
Other answers
Your problem is the function call calculateAverage ( inFile&, outFile&, double&); the function expects a reference to an ifstream, a reference to an ofstream, and a reference to a double. Not literally '<ifstream>&' your function call should look something like calculateAverage ( inFile, outFile, scoreAvg); instead (replace scoreAvg with whatever variable you actually need to use)
PC
@PC is correct Also in you code, dont use "while (true)" to declare a loop Do something like this, which will result in you not needing the "break" statement within the loop __ while (inFile.good() ) // ^that checks if your at the end of file or not {// Start of while loop inFile >> name; outFile << setw( 10 ) << left << name; calculateAverage ( inFile, outFile, scoreAvg); outFile << setw( 10 ) << right << scoreAvg; outFile << setw( 6 ) << right << 'calculateGrade( scoreAvg)'<<endl; counter++; average += scoreAvg; }// End of While loop
.#include <keperkjr>
@PC is correct Also in you code, dont use "while (true)" to declare a loop Do something like this, which will result in you not needing the "break" statement within the loop __ while (inFile.good() ) // ^that checks if your at the end of file or not {// Start of while loop inFile >> name; outFile << setw( 10 ) << left << name; calculateAverage ( inFile, outFile, scoreAvg); outFile << setw( 10 ) << right << scoreAvg; outFile << setw( 6 ) << right << 'calculateGrade( scoreAvg)'<<endl; counter++; average += scoreAvg; }// End of While loop
.#include
there is no definition of function calculateAverage, and also other functions. Rather function names are different. First call them with correct names.
James Bond
there is no definition of function calculateAverage, and also other functions. Rather function names are different. First call them with correct names.
James Bond
Related Q & A:
- How can I fix parser Error in ASP.NET?Best solution by parse.com
- How do I fix the "Specified path is too long" error?Best solution by itcsupport.wordpress.com
- What is server error code 40402?Best solution by Yahoo! Answers
- What does Sync error mean?Best solution by Yahoo! Answers
- What's financial aid suspension and how do you fix it?Best solution by ehow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.