Hi Everybody,
I am brand new to C++ and am having a bit of trouble accomplishing what should be a simple task. What this code is meant to do is count the number of students in a given input text file. I figured putting in a function was a good idea, to reduce the clutter in the main function. This code is actually an excerpt from the whole program, but should serve the right purpose anyway. The error is occurring in both the main code, and this excerpt. I am not sure why it is happening or how to fix it, I would appreciate the help of anyone who is willing.
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void student_counter(ifstream input2, int& student_count);
int main()
{
string studentName;
int test1,test2,test3,test4,test5;
char grade = ' ';
int student_average = 0;
int student_count = 0;
double class_average = 0;
int class_total = 0;
ifstream infile; //input file stream variable
ofstream outfile; //output file stream variable
infile.open("studentgrades.txt"); //open input file
outfile.open("results.out"); //open output file
student_counter(infile,student_count);
infile.close();
outfile.close();
return 0;
}
void student_counter(ifstream input2, int& student_count)
{
string studentName;
int test1,test2,test3,test4,test5;
//While there is still data to be read in the input file do the following:
while (input2)
{
input2 >> studentName >> test1 >> test2 >> test3 >> test4 >> test5;
if (studentName == "end")
{
break;
}
student_count++;
}
}