I can not figure out how to go to the next line. In the data we read in number of test on the 1st line then student names followed by their test scores on the following lines. My problem is I can only get the first student and his average and that is it. Any help would be nice thanks.
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int tests;
int min;
int testScores;
int counter;
float sum;
float average;
string studentName;
ifstream inData;
inData.open("students.dat");
if(!inData) // file couldn't be opened
cout << "Error: file could not be opened" << endl;
min = 200;
sum = 0;
counter = 0;
inData >> tests;
inData >> studentName;
while (inData)
{
cout << "Student's Name:" << studentName << endl;
inData >> testScores;
while (counter < tests)
{
if (min > testScores)
min = testScores;
sum = sum + testScores;
inData >> testScores;
counter++;
}
sum = sum - min;
average = sum / (tests-1);
cout << "Test Average is:" << average << endl;
inData >> studentName;
}
return 0;
}