Hi, I am currently working on an assignment that asks me to input test scores for 5 students for three tests using multi dimensional arrays and determined the average test score as well as the highest and lowest test score for each student. I was able to determine the average for each student however I am having trouble finding the highest and lowest score for each student. Could somebody please help me? I have included the question in the program. Thank you
//Ask the user to input the test scores of 5 students for 3 tests.
//Then for each student compute the average test score,
//as well as the student's highest and lowest test score
//and print them out.
#include <iostream>
usingnamespace std;
constint STUDENTS = 5;
constint TESTS = 3;
int main ()
{
int score[STUDENTS][TESTS];
int s; //Represents students
int t; //Represents tests
int highest;
int lowest;
float Average = 0;
cout << "Input tests scores of 5 students for 3 tests: \n\n";
for (s=0; s < STUDENTS; s++)
{
int Total = 0;
for (t=0; t < TESTS; t++)
{
cout << "Student #" << s+1 << " - Test #" << t+1 << ": ";
cin >> score[s][t];
Total += score[s][t];
}
Average = float(Total) / TESTS;
cout << "The average score is " << Average << endl << endl;
}
highest = score[0][0];
lowest = score[0][0];
cout << "===============================================================================\n\n";
for (s=0; s < STUDENTS; s++)
{
for (t=0; t < TESTS; t++)
{
if(score[s][t] > highest)
highest = score[s][t];
elseif (score[s][t] < lowest)
lowest = score[s][t];
}
cout << "The highest score for student #" << s+1 << " is " << highest << endl;
cout << "The lowest score for student #" << s+1 << " is " << lowest << endl << endl;
}
return 0;
}
Hey, the problem is that you're not restarting the variables for each student. You should do that per outter loop iteration to avoid testing the test scores of student 1 with student 2's scores for example. Add the following after your 2 cout statements on line 62: