I'm making a student database using array based lists. I'm having trouble with making the list size created by the user. I have a for loop there now but once I put it there, I get an error saying aStudent is an undeclared variable and I don't understand why. There wasn't an error before the for loop.
int* stud = new int[size];
// creating a record
int b;
for (int b = 0; b < size; b++)
{
Student aStudent;
cout << "Student's name? ";
getline(cin, aStudent.name);
cout << "Student's ID? ";
cin >> aStudent.id;
cin.ignore(1000, 10);
cout << "Student's GPA? ";
cin >> aStudent.gpa;
cin.ignore(1000, 10);
}
// skipping separator
cin.ignore(1000, 10);
// adding record to list
if (nStudents < MAX_STUDENTS)
student[nStudents++] = aStudent;
// sorting by gpa
for (int i = 0; i < nStudents; i++)
{
for (int j = i + 1; j < nStudents; j++)
{
if (student[i].gpa > student[j].gpa)
{
Student temp = student [i];
student [i] = student[j];
student [j] = temp;
}
}
}
printStudents(student, nStudents);
cout << endl;
return 0;
}