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 this approach to calculate 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 formal parameter variable, and validate it. If a judge’s score entered is lower than 0 or higher than 10, ask the judge to enter it again until he or she enters the valid score (using priming read and the pre-test loop DO WHILE for the input validations). This function should be called by the main( ) once for each of the five judges.
void calcScore( ) should calculate and display 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 the main( ) and should be passed the five scores.
The last two functions, described below, should be called by the calcScore( ), which uses the returned information to determine which of the score to drop.
double findLowest( ) should find and return the lowest of the five scores passed to it.
double findHighest( ) should find and return the highest of the five scores passed to it.
Here's my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#include <iostream>
using namespace std;
double getJudgeData(double score) {
cout << "Judge 1 please enter your score: ";
cin >> score;
while (score < 0.0 || score > 10.0) {
cout << "The score entered must be between 0 and 10. Please enter again." << endl;
cout << "\nJudge 1 please enter your score: ";
cin >> score;
}
return score;
}
double getJudgeData1(double score1) {
cout << "Judge 2 please enter your score: ";
cin >> score1;
while (score1 < 0.0 || score1 > 10.0) {
cout << "The score entered must be between 0 and 10. Please enter again." << endl;
cout << "\nJudge 2 please enter your score: ";
cin >> score1;
}
return score1;
}
double getJudgeData2(double score2) {
cout << "Judge 3 please enter your score: ";
cin >> score2;
while (score2 < 0.0 || score2 > 10.0) {
cout << "The score entered must be between 0 and 10. Please enter again." << endl;
cout << "\nJudge 3 please enter your score: ";
cin >> score2;
}
return score2;
}
double getJudgeData3(double score3) {
cout << "Judge 4 please enter your score: ";
cin >> score3;
while (score3 < 0.0 || score3 > 10.0) {
cout << "The score entered must be between 0 and 10. Please enter again." << endl;
cout << "\nJudge 4 please enter your score: ";
cin >> score3;
}
return score3;
}
double getJudgeData4(double score4) {
cout << "Judge 5 please enter your score: ";
cin >> score4;
while (score4 < 0.0 || score4 > 10.0) {
cout << "The score entered must be between 0 and 10. Please enter again." << endl;
cout << "\nJudge 5 please enter your score: ";
cin >> score4;
}
return score4;
}
double findHighest() {
double score, score1, score2, score3, score4;
double highest = 0;
if (score > highest)
highest = score;
else if (score1 > score)
highest = score1;
else if (score2 > score)
highest = score2;
else if (score3 > score)
highest = score3;
else if (score4 > score)
highest = score4;
return highest;
}
double findLowest() {
double score, score1, score2, score3, score4;
double lowest = 10;
if (score < lowest)
lowest = score;
else if (score1 < score)
lowest = score1;
else if (score2 < score)
lowest = score2;
else if (score3 < score)
lowest = score3;
else if (score4 < score)
lowest = score4;
return lowest;
}
void calcScore() {
double score, score1, score2, score3, score4;
double lowest;
double highest;
double findHighest(highest);
double findLowest(lowest);
double totalScore = score + score1 + score2 + score3 + score4;
double avgScore = (totalScore - highest - lowest)/3;
cout << "\nThe contestant's average score is: " << avgScore << endl;
}
int main() {
double score, score1, score2, score3, score4;
double lowest, highest;
getJudgeData(score);
getJudgeData1(score1);
getJudgeData2(score2);
getJudgeData3(score3);
getJudgeData4(score4);
calcScore();
system("PAUSE");
return 0;
}
|
The outputs for everything comes out to 0 and I don't know why.
I put to figure out the outputs:
1 2 3 4 5 6 7 8
|
cout << "score " << score << endl;
cout << "score1 " << score1 << endl;
cout << "score2 " << score2 << endl;
cout << "score3 " << score3 << endl;
cout << "score4 " << score4 << endl;
cout << "highest = " << highest << endl;
cout << "lowest = " << lowest << endl;
cout << "totalScore = " << totalScore << endl;
|
any idea why? or what am I doing wrong?