Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lowest Score Drop Write a program in C++ language that calculates the average of a group of test scores, where the lowest score in the

Lowest Score Drop

Write a program in C++ language 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(int &) 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(int, int, int, int, int) 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(int, int, int, int, int) 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 which of the five scores to drop. Input Validation: Do not accept test scores lower than 0 or higher than 100.

My code is as follows, no arrays allowed, sadly.

#include
#include
using namespace std;
 
void getScore(int&);
void calcAverage(int, int, int, int, int);
int findLowest(int score1, int score2, int score3, int score4, int score5);
 
int main(){
 
 int main(){
 int score1, score2, score3, score4, score5;
 
 getScore(score1);
 getScore(score2);
 getScore(score3);
 getScore(score4);
 getScore(score5);
 calcAverage(score1, score2, score3, score4, score5);
 system("pause");
 return 0;
}
 
void getScore(int &score){
 
 cout << "Please enter a score between 0 - 100: ";
 cin >> score;
 
 while (score < 0 || score > 100){
 cout << "Error - enter a score between 0 - 100: ";
 cin >> score;
 }
}
 
int findLowest(int score1, int score2, int score3, int score4, int score5){
 int lowest = score1;
 
 if (score2 < lowest)
 lowest = score2;
 if (score3 < lowest)
 lowest = score3;
 if (score4 < lowest)
 lowest = score4;
 if (score5 < lowest)
 lowest = score5;
 
 cout << "The lowest score is " << lowest << endl;
 return lowest;
}
 
void calcAverage(int score1, int score2, int score3, int score4, int score5){
 int lowest = findLowest(score1, score2, score3, score4, score5); 
 double average = (((float)score1 + score2 + score3 + score4 + score5) - lowest) / 4.0;
 
 cout << setw(4); 
 cout << fixed << showpoint << setprecision(2);
 cout << "The average of the 4 highest scores is " << average << endl;
}
 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions