I am running into a baffling problem with my code. I am supposed to write a program to average the test scores for an entire class of students. In each case, the student should have taken 5 tests. You are to average the 5 tests.
The program run should look like this.
How many students are in the class ?
3
Enter five test scores for student number 1 90 90 70 90 80 The average for student number 1 is 84
Enter five test scores for student number 2 100 60 60 90 80 The average for student number 2 is 78
Enter five test scores for student number 3 90 70 50 70 90 The average for student number 3 is 74
Here is what I have:
#include <iostream>
#include <iomanip>
using namespace std;
void handleOneStudent(int N);
int main()
{
int NumberOfStudents;
cout << "How many students are in the class ?" << endl;
cin >> NumberOfStudents;
cout << endl;
for (int i=1; i <= NumberOfStudents; i++)
handleOneStudent(i);
return 0;
}
void handleOneStudent(int N)
{
const int num_quizzes = 5;
int score[num_quizzes];
double average;
cout << setprecision(2)
<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint);
cout << "Enter five test scores for student number " << N << endl;
cin >> score[num_quizzes];
average = (score[1] + score[2] + score[3] + score[4] + score[5])/5;
cout << endl << endl;
cout << "The average for student number " << N << " is " << average << endl;
}
When I run the code I get the following error:
Error message:
Debug error!
Run-Time Check Failure #2 - Stack around the variable 'score' was corrupted.