I'm trying to get the numbers of lines of input file to be size of array, but it keeps giving error that expression of the array must be constant. Here is my code:
int main() {
int count = 0;
string line;
ifstream infile("students.dat");
while (getline(infile, line))
count++;
cout << "Numbers of input is: " << count << endl;
const int size = count;
double max, min, average;
int freshman, sophomore, junior, senior;
string firstname[size];
string lastname[size];
string year[size];
double grade[size];
cout << "name\n";
for (int i = 0; i < size; i++) {
infile >> firstname[i] >> lastname[i]
>> year[i] >> grade[i];
}
max = FindMax(size, grade);
cout << "\nHighest grade: " << max;
min = FindMin(size, grade);
cout << "\nLowest grade: " << min;
average = FindAvg(size, grade);
cout << "\nClass average: " << average;
FindYear(size, year);
infile.close();
return 0;
}
Sample input file:
John Omi freshman 66
Katy Hill sophomore 55
Jeff Ozco freshman 90