Judge average Score

9. Star Search
A particular talent competition has five 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 three remaining scores. Write a program that uses these rules to calculate and display a contestant’s score. It should include the following functions:
void getJudgeData() 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 five judges.
Make the following change to void getJudgeData( ).
The function should take in 2 parameters, not 1, as specified above
The first parameter should be a string that holds the values "Judge 1", "Judge 2".. and so on.
The second parameter should follow specifications shown above.
The getJudgeData function should ensure that:
score is numeric
score is >= 0
score is <= 10

double getAverage() should calculate and return the average of the three 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 five scores.
Invoke the getLowest and getHighest function from this function in order to drop highest and lowest scores before calculating average.

In int main, invoke the getHighest, getLowest and getAverage functions and print out the values returned by these functions. Average, highest and lowest values must be printed in the int main function. All scores must be printed out to 2 places after the decimal place




#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;

void getJudgeData(string jname, double &score);
double getAverage(double score1, double score2, double score3, double score4, double score5);
double findLowest(double score1, double score2, double score3, double score4, double score5);
double findHighest(double score1, double score2, double score3, double score4, double score5);

int main()
{
double score1, score2, score3, score4, score5, average_sc, lowest_sc, highest_sc;

getJudgeData("Judge 1", score1);
{
cout << "Data entry for Judge 1. Score must be in the range 0 - 10 ";
cin >> score1;

while (cin.fail())
{
if (cin.fail())
{
cin.clear();
cin.ignore(100, '\n');
cout << "Invalid. Input must be numeric. Please re-enter score\n";
cout << "Data entry for Judge 1. Score must be in the range 0 - 10 ";
cin >> score1;
}
}
while (score1 < 0.0 || score1 > 10.0)
{

cout << "Invalid. Input must be numeric please re-enter score." << endl;
cout << "Data entry for Judge 1. Score must be in the range 0 - 10: ";
cin >> score1;
}

return score1;
}
getJudgeData("Judge 2", score2);
{
cout << "Judge 2 enter your score: ";
cin >> score2;

while (score2 < 0.0 || score2 > 10.0)
{
cout << "The score entered must be a number between 0 and 10. Please re-enter score." << endl;
cin >> score2;
}
return score2;
}
getJudgeData("Judge 3", score3);
{
cout << "\nData entry for Judge 3. Score must be in the range of 0 - 10: ";
cin >> score3;

while (score3 < 0.0 || score3 > 10.0)
{
cout << "The score entered must be a number between 0 and 10. Please re-enter score." << endl;
cin >> score3;
}
return score3;
}
getJudgeData("Judge 4", score4);
{
cout << "\nJudge 4 enter your score: ";
cin >> score4;

while (score4 < 0.0 || score4 > 10.0)
{
cout << "The score entered must be a number between 0 and 10. Please re-enter score." << endl;
cin >> score4;
}
return score4;
}
getJudgeData("Judge 5", score5);
{
cout << "\nData entry for Judge 5. Score must be in the range of 0 - 10: ";
cin >> score5;

while (score5 < 0.0 || score5 > 10.0)
{
cout << "The score entered must be a number between 0 and 10. Please re-enter score." << endl;
cin >> score5;
}
return score5;
}

double getAverage(double score1, double score2, double score3, double score4, double score5);
{
highest_sc = findHighest(score1, score2, score3, score4, score5);
lowest_sc = findLowest(score1, score2, score3, score4, score5);
}
double findLowest(double score1, double score2, double score3, double score4, double score5);
{
double score1, score2, score3, score4, score5;
double lowest_sc = 10;

if (score1 < lowest_sc)
lowest_sc = score1;
else if (score2 < score1)
lowest_sc = score2;
else if (score3 < score1)
lowest_sc = score3;
else if (score4 < score1)
lowest_sc = score4;
else if (score5 < score1)
lowest_sc = score5;

return lowest_sc;
}

double findHighest(double score1, double score2, double score3, double score4, double score5);
{
double score1, score2, score3, score4, score5;
double highest_sc = 0;

if (score1 > highest_sc)
highest_sc = score1;
else if (score2 > score1)
highest_sc = score2;
else if (score3 > score1)
highest_sc = score3;
else if (score4 > score1)
highest_sc = score4;
else if (score5 > score1)
highest_sc = score5;

return highest_sc;
}

cout << "\nAverage = " << average_sc << endl;
cout << "Lowest = " << lowest_sc << endl;
cout << "Highest = " << highest_sc << endl;

return 0;
}

void getAverage()
{
double score1, score2, score3, score4, score5;
double lowest_sc;
double highest_sc;

double findHighest(highest_sc);
double findLowest(lowest_sc);

double average_sc = (((score1 + score2 + score3 + score4 + score5) - findHighest(highest_sc) - findLowest(lowest_sc) / 3);

return getAverage();

}

Last edited on
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/
You can edit your post, highlight your code and click the <> button on the right.

I'd recommend that you revise on the basics first.
http://www.cplusplus.com/doc/tutorial/functions/
Topic archived. No new replies allowed.