while (student4Scores[count] < 0 || student4Scores[count] > 100)
{
cout << "Please enter a score between 0-100.\n";
cin >> student4Scores[count];
}
}
//Calling the getAverage function
average = getAverage(student0Scores, TESTS);
Grade = getGrade(average);
cout << "\n";
cout << "The average test score for " << student[0] << " is: " << average << " and the lettergrade is: " << Grade;
cout << "\n";
average = getAverage(student1Scores, TESTS);
Grade = getGrade(average);
cout << "\n";
cout << "The average test score for " << student[1] << " is: " << average << " and the lettergrade is: " << Grade;
cout << "\n";
average = getAverage(student2Scores, TESTS);
Grade = getGrade(average);
cout << "\n";
cout << "The average test score for " << student[2] << " is: " << average << " and the lettergrade is: " << Grade;
cout << "\n";
average = getAverage(student3Scores, TESTS);
Grade = getGrade(average);
cout << "\n";
cout << "The average test score for " << student[3] << " is: " << average << " and the lettergrade is: " << Grade;
cout << "\n";
average = getAverage(student4Scores, TESTS);
Grade = getGrade(average);
cout << "\n";
cout << "The average test score for " << student[4] << " is: " << average << " and the lettergrade is: " << Grade;
cout << "\n";
cout << endl;
system("PAUSE");
return 0;
}
double getAverage(double scores[], int TESTS) //Get average function
{
double avg, total=0;
int count;
for (count = 0; count < TESTS; count++)
{
total += scores[count];
}
avg = total / TESTS;
return avg;
}
char getGrade(double avg) //Get the letter grade based on the average.
{
const int A_SCORE = 90,
B_SCORE = 80,
C_SCORE = 70,
D_SCORE = 60;
char lettergrade;
if (avg >= A_SCORE)
lettergrade = 'A';
else
if (avg >= B_SCORE)
lettergrade = 'B';
else
if (avg >= C_SCORE)
lettergrade = 'C';
else
if (avg >= D_SCORE)
lettergrade = 'D';
else
if (avg < D_SCORE)
lettergrade = 'F';