I'm currently taking a C++ class and this is a task we have to complete. I've got most of it completed, but I have one problem.

The way the program is suppose to work is it's suppose to read an infile that has an unknown number of students with their 5 best test grades. It's suppose to calculate the average for each student, then the average for the all the students. It's suppose to then count the numbers of A's, B's C's...etc there are within the students.

Here's what I have...

Code:

void main ()
{ ... calls all functions and any couts ..}
void take_input(int &test1, int &test2, int &test3, int &test4, int &test5, int &students, string &student)
{
int numOfStud =0;
ifstream inData;
inData.open("in.txt");
while (!inData.eof())
{
inData>>student>>test1>>test2>>test3>>test4>>test5;
cout<<student<<test1<<test2<<test3<<test4<<test5<<endl;
students++;
}
}
float calculateAverage(int &test1, int &test2, int &test3, int &test4, int &test5, int &students, string &student, float &average)
{
int sum;
float classAve, x = 0;
for (int i = 1; i <= students; i++)
{
sum = test1 + test2 + test3 + test4 + test5;
average = static_cast <float> (sum) / 5;
x = x + average;
}
classAve = x / students;
return classAve;
}
void calculateGrade(int &test1, int &test2, int &test3, int &test4, int &test5, int &countA, int &countB, int &countC, int &countD, int &countF, int &students, string &student, float &average)
{
float grade;
for (int i = 1; i <= students; i++)
{
grade = average;
if ((90 <= grade) && (grade <= 100))
countA++;
else if ((80 <= grade) && (grade <= 89.99))
countB++;
else if ((70 <= grade) && (grade <= 79.99))
countC++;
else if ((60 <= grade) && (grade <= 69.99))
countD++;
else if ((0 <= grade) && (grade <= 59.99))
countF++;
}
}

The problem I'm having is that it only takes the last person's grade and does the calculations with those numbers.

Example:

infile:

bob 88 96 85 76 99

suzy 91 84 72 94 74

johnney 100 98 79 93 86

outfile:

johnney 100 98 79 93 86

johnney 100 98 79 93 86

johnney 100 98 79 93 86

A appeared 3 times.

B appeared 0 times.

C appeared 0 times.

D appeared 0 times.

F appeared 0 times.

In reality, Bob and Suzy got B's. I narrowed it down to there being something wrong with my loop, but I can't figure it out.

Any help would be appreciate it. Thanks in advance!