Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions:
• void getScore() should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered.
• void calcAverage() should calculate and display the average of the four highest
scores. This function should be called just once by main, and should be passed the
five scores.
• int findLowest() should find and return the lowest of the five scores passed to it.
It should be called by calcAverage(), which uses the function to determine one of the five scores to drop.
Input Validation: Do not accept test scores lower than 0 or higher than 100.
#include <iostream>
#include <iomanip>
using namespace std;
void getScore (int,int,int,int,int);
void CalcAverage (int,int,int,int,int);
int FindLowest (int,int,int,int,int);
int main()
{
int TestScore1, TestScore2, TestScore3, TestScore4, TestScore5;
getScore (TestScore1,TestScore2,TestScore3,TestScore4,TestScore5);
CalcAverage (TestScore1,TestScore2,TestScore3,TestScore4,TestScore5);
return 0;
}
void getScore (int TestScore1,int TestScore2,int TestScore3,int TestScore4,int TestScore5)
{
cout <<" Enter your first test score: ";
cin >> TestScore1;
cout <<" Enter your second test score: ";
cin >> TestScore2;
cout <<" Enter your third test score: ";
cin >> TestScore3;
cout <<" Enter your fourth test score: ";
cin >> TestScore4;
cout <<" Enter your fifth test score: ";
cin >> TestScore5;
while (TestScore < 0 || TestScore > 100) {
cout <<" Please enter a valid score: ";
cin >> TestScore;
}
}
void CalcAverage (int Scr1,int Scr2,int Scr3,int Scr4,int Scr5);
{
int sum , lowest;
double avg;
lowest = FindLowest ( Scr1,Scr2,Scr3,Scr4,Scr5);
sum = Scr1 + Scr2 + Scr3 + Scr4 + Scr5 - lowest;
avg = sum / 4.0;
cout << setw(4) << fixed << showpoint << setprecision (2);
cout <<" The average of the 4 highest scores are: "<< avg << endl;
}
int FindLowest (int Scr1,int Scr2,int Scr3,int Scr4,int Scr5)
{
int lowest = Scr1;
if (Scr2 < lowest) {
lowest = Scr2;
}
else if (Scr3 < lowest) {
lowest = Scr3;
}
else if (Scr4 < lowest) {
lowest = Scr4;
}
else if (Scr5 < lowest) {
lowest = Scr5;
}
cout <<" The lowest test score is: "<< lowest << endl;
return lowest;
}