process may continue as long as the user wants to enter scores for another conte
ID: 3761749 • Letter: P
Question
process may continue as long as the user wants to enter scores for another contestant. Write a program that uses this method to calculate a contestant’s score.
Include the following functions in your program:
Void getJudgesData() should ask the user for a judge’s score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the judges.
Void calcScore() should calculate and display the average of the three scores that remain after dropping the highest and lowest scores. This function should be called once in the main and you should pass 5 scores to it.
/// here is the code I need to figure out how to get the cout statement "Enter 5 scores for the contestant and I will drop the lowest and highest to find the average score: " to only appear once in the debugging window but repeat the judges one 5 times. And after averaging scores have it ask "Do you want to continue with anther contestant (y/n) if y
then have the program ask for 5 more scores and average them again.
and then ask " do you want to continue wtih anther contestant (y/n) and unless its n it would loop again for 5 more scores drop the lowest and highest and average them. ///////
#include <iostream>
#include <iomanip>
using namespace std;
void getJudgeData(double &a);
void calcScore(double a, double b, double c, double d, double e);
double findLowest(double a, double b, double c, double d, double e);
double findHighest(double a, double b, double c, double d, double e);
void getJudgeData(double &score) {
if ( 1 > 0 ) {
cout << "Enter 5 scores for the contestant and I will drop the lowest and highest to find the average score: " <<endl;
}
if ( 2 > 0 ) {
cout << "Enter the judge's score: ";
cin >> score;
cout << endl;
}
}
void calcScore(double a, double b, double c, double d, double e) {
double low = findLowest(a,b,c,d,e);
double sum = a + b + c + d + e - findLowest(a,b,c,d,e) - findHighest(a,b,c,d,e);
double average = sum / 3;
cout << "Average score is " << average << endl;
}
double findLowest(double a, double b, double c, double d, double e) {
double min = a;
if(b < min) {
min = b;
}
if(c < min) {
min = c;
}
if(d < min) {
min = d;
}
if(e < min) {
min = e;
}
return min;
}
double findHighest(double a, double b, double c, double d, double e) {
double max = a;
if(b > max) {
max = b;
}
if(c > max) {
max = c;
}
if(d > max) {
max = d;
}
if(e > max) {
max = e;
}
return max;
}
int main()
{
double score1; // To hold the 1st score.
double score2; // To hold the 2nd score.
double score3; // To hold the 3rd score.
double score4; // To hold the 4th score.
double score5; // To hold the 5th score.
// Get the five judges scores.
getJudgeData(score1);
getJudgeData(score2);
getJudgeData(score3);
getJudgeData(score4);
getJudgeData(score5);
// Display the average score after dropping
// the lowest and highest scores.
calcScore(score1, score2, score3, score4, score5);
system("PAUSE");
return EXIT_SUCCESS;
}
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
void getJudgeData(double &a);
void calcScore(double a, double b, double c, double d, double e);
double findLowest(double a, double b, double c, double d, double e);
double findHighest(double a, double b, double c, double d, double e);
void getJudgeData(double &score) {
cout << "Enter the judge's score: ";
cin >> score;
cout << endl;
}
void calcScore(double a, double b, double c, double d, double e) {
double low = findLowest(a,b,c,d,e);
double high = findHighest(a,b,c,d,e);
double sum = a + b + c + d + e - low - high;
double average = sum / 3;
cout<<"Lowest is: "<<low<<endl;
cout<<"Highest is: "<<high<<endl;
cout << "Average score is " << average << endl;
}
double findLowest(double a, double b, double c, double d, double e) {
double min = a;
if(b < min) {
min = b;
}
if(c < min) {
min = c;
}
if(d < min) {
min = d;
}
if(e < min) {
min = e;
}
return min;
}
double findHighest(double a, double b, double c, double d, double e) {
double max = a;
if(b > max) {
max = b;
}
if(c > max) {
max = c;
}
if(d > max) {
max = d;
}
if(e > max) {
max = e;
}
return max;
}
int main()
{
double score1; // To hold the 1st score.
double score2; // To hold the 2nd score.
double score3; // To hold the 3rd score.
double score4; // To hold the 4th score.
double score5; // To hold the 5th score.
while (true) {
cout << "Enter 5 scores for the contestant and I will drop the lowest and highest to find the average score: " <<endl;
// Get the five judges scores.
getJudgeData(score1);
getJudgeData(score2);
getJudgeData(score3);
getJudgeData(score4);
getJudgeData(score5);
// Display the average score after dropping
// the lowest and highest scores.
calcScore(score1, score2, score3, score4, score5);
cout<<" Enter y to continue and n to quit: ";
char ch;
cin>>ch;
if (tolower(ch) == 'n') {
break;
}
cout<<" ";
}
system("PAUSE");
return EXIT_SUCCESS;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.