I think the problem is an access violation but I just can't seem to find it. Here is the function.
// Structure
struct TestScores
{
char Name[40]; // Student name
int Idnum; // Student ID number
double *Tests; // Pointer to an array of test scores
double Average; // Average test score
char Grade; // Course grade
};
student is dynamically created and points to TestScores. In this function, let's say totalStudents is 2 and there are 5 tests. The access violation prompt screen shows up when it finishes one loop of one student for the test scores. Then it does one more question on what was the score for student 2 on test 1 but it stops right there.
// Gets ID numbers, names, and test scores of every student
void getId_Scores(TestScores *student, int totalStudents, int tests)
{
int count; // Counter
// Loop will get student names
for (count = 0; count < totalStudents; count++)
{
cout << "Enter student " << count + 1 << "'s name. ";
cin >> student[count].Name;
}
// Loop will collect ID numbers of all students
for (count = 0; count < totalStudents; count++)
{
cout << "Enter " << student[count].Name << "'s ID number: ";
cin >> student[count].Idnum;
// Input Validation
while (student[count].Idnum < 0)
{
cout << "You entered a negative ID number. Enter again. ";
cin >> student[count].Idnum;
}
}
/* Loop will collect test scores of all students.
Big loop for number of students and small loop for
number of tests. */
for (int studNum = 0; studNum < totalStudents; studNum++)
{
for (int testNum = 0; testNum < tests; testNum++)
{
cout << "Enter " << student[studNum].Name << "'s score on test ";
cout << testNum + 1 << ": ";
cin >> student[studNum].Tests[testNum];
// Input Validation
while (student[studNum].Tests[testNum] < 0)
{
cout << "You entered a negative test score. Enter again. ";
cin >> student[studNum].Tests[testNum];
}
}
}
}