Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that calculates the average of 5 test scores, where the lowest s

ID: 3802795 • Letter: W

Question

Write a program that calculates the average of 5 test scores, where the lowest score in the group is dropped. It should use the following functions: void getScore0 should ask the user for a test score, store it in a reference paramater variable, and validate it. This function should be called by main once for each of the five scores to be entered. void calcAverage0 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 findLowest0 should find and return the lowest of the five scores passed to it. It should be called by calcAverage0 function, which uses the function to determine which of the five scores to drop. Input Validation: Do not accept test scores lower than 0 or higher than 100

Explanation / Answer

#include <iostream>

using namespace std;
double getScore() {
double score;
cout<<"Enter Score: ";
cin >> score;
if(score < 0 || score>100){
cout<<"Invalid score. Score sould be between 0 and 100"<<endl;
return -1;
}
return score;
}
double findLowest(double scores[], int size) {
double min =scores[0];
for(int i=0; i<size; i++){
if(min > scores[i]){
min = scores[i];
}
}
return min;
}
void calcAverage(double scores[], int size){
double sum = 0;
for(int i=0; i<size; i++){
sum = sum + scores[i];
}
sum = sum - findLowest(scores, size);
cout<<"The average scores after removing lowest score: "<<(sum/4)<<endl;
}

int main()
{
double scores[5];
for(int i=0; i<5; i++) {
scores[i] = getScore();
if(scores[i] == -1){
i--;
}
}
calcAverage(scores, 5);
  
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter Score: 44                                                                                                                                                                                                                                                        

Enter Score: 55                                                                                                                                                                                                                                                        

Enter Score: 66                                                                                                                                                                                                                                                        

Enter Score: 77                                                                                                                                                                                                                                                        

Enter Score: 88                                                                                                                                                                                                                                                        

The average scores after removing lowest score: 71.5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote