The Question and the code below:
Question
--------
A talent competition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3 are allowed. A performer's final score is determined by dropping the highest and lowest score received, then averaging the 3 remaining scores. Write a program that uses this method to calculate a contestant's score. It should include the following functions:
void getJudgeData() -- This 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 5 judges.
double calcScore() -- This should calculate and display the average of the 3 scores that remain after dropping the highest and lowest scores the performer received. This function should be called just once by main, and should be passed the 5 scores.
The last two functions, described below, should be called by calcScore, which uses the returned information to determine which of the scores to drop.
int findLowest() -- This should find and return the lowest of the 5 scores passed to it.
int findHighest() -- This should find and return the highest of the 5 scores passed to it.
Input Validation: Do not accept judge scores lower than 0 or higher than 10.
Code
----
#include <iostream>
using namespace std;
void getJudgeData(double&, double&, double&, double&, double&);
double calcScore();
int findLowest(double value1,double value2,double value3,double value4,double value5);
int findHighest(double value1,double value2,double value3,double value4,double value5);
int main()
{
double val1,val2,val3,val4,val5;
getJudgeData(val1,val2,val3,val4,val5);
double calcScore();
return 0;
}
void getJudgeData(double& judval1, double& judval2, double& judval3, double& judval4, double& judval5)
{
cout << "Judge 1 : Enter the score of the performer." << endl;
cin >> judval1;
while (judval1 < 0 && judval1 > 10)
{
cout << "The score must be between 0 and 10." << endl;
cout << "Enter it again." << endl;
cin >> judval1;
}
cout << "Judge 2 : Enter the score of the performer." << endl;
cin >> judval2;
while (judval2 < 0 && judval2 > 10)
{
cout << "The score must be between 0 and 10." << endl;
cout << "Enter it again." << endl;
cin >> judval2;
}
cout << "Judge 3 : Enter the score of the performer." << endl;
cin >> judval3;
while (judval3 < 0 && judval3 > 10)
{
cout << "The score must be between 0 and 10." << endl;
cout << "Enter it again." << endl;
cin >> judval3;
}
cout << "Judge 4 : Enter the score of the performer." << endl;
cin >> judval4;
while (judval4 < 0 && judval4 > 10)
{
cout << "The score must be between 0 and 10." << endl;
cout << "Enter it again." << endl;
cin >> judval4;
}
cout << "Judge 5 : Enter the score of the performer." << endl;
cin >> judval5;
while (judval5 < 0 && judval5 > 10)
{
cout << "The score must be between 0 and 10." << endl;
cout << "Enter it again." << endl;
cin >> judval5;
}
}
double calcScore()
{
double average;
double value1,value2,value3,value4,value5;
findLowest(value1,value2,value3,value4,value5);
findHighest(value1,value2,value3,value4,value5);
cout << findLowest;
cout << findHighest;
cout << "The average score of the performer is " << average << endl;
}
int findLowest(double value1,double value2,double value3,double value4,double value5)
{
double lowest;
if (value1 < value2 && value1 < value3 && value1 < value4 && value1 < value5)
lowest = value1;
if (value2 < value1 && value2 < value3 && value2 < value4 && value2 < value5)
lowest = value2;
if (value3 < value1 && value3 < value2 && value3 < value4 && value3 < value5)
lowest = value3;
if (value4 < value1 && value4 < value2 && value4 < value3 && value4 < value5)
lowest = value4;
if (value5 < value1 && value5 < value2 && value5 < value3 && value5 < value4)
lowest = value5;
return lowest;
}
int findHighest(double value1,double value2,double value3,double value4,double value5)
{
double highest;
if (value1 > value2 && value1 > value3 && value1 > value4 && value1 > value5)
highest = value1;
if (value2 > value1 && value2 > value3 && value2 > value4 && value2 > value5)
highest = value2;
if (value3 > value1 && value3 > value2 && value3 > value4 && value3 > value5)
highest = value3;
if (value4 > value1 && value4 > value2 && value4 > value3 && value4 > value5)
highest = value4;
if (value5 > value1 && value5 > value2 && value5 > value3 && value5 > value4)
highest = value5;
return highest;
}

New Topic/Question
Reply




MultiQuote










|