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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include <iostream>
#include <math.h>
using namespace std;
double getJudgeData1(double score1)
{
cout << "Judge 1 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 1 please enter your score: ";
cin >> score1;
}
return score1;
}
double getJudgeData2(double score2)
{
cout << "Judge 2 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 2 please enter your score: ";
cin >> score2;
}
return score2;
}
double getJudgeData3(double score3)
{
cout << "Judge 3 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 3 please enter your score: ";
cin >> score3;
}
return score3;
}
double getJudgeData4(double score4)
{
cout << "Judge 4 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 4 please enter your score: ";
cin >> score4;
}
return score4;
}
double getJudgeData5(double score5)
{
cout << "Judge 5 please enter your score: ";
cin >> score5;
while (score5 < 0.0 || score5 > 10.0)
{
cout << "The score entered must be between 0 and 10. Please enter again." << endl;
cout << "\nJudge 5 please enter your score: ";
cin >> score5;
}
return score5;
}
double findHighest()
{
double score1, score2, score3, score4, score5;
double highest = 0;
if (score1 > score2 && score1 > score3 && score1 > score4 && score1 > score5)
highest = score1;
if (score2 > score1 && score2 > score3 && score2 > score4 && score2 > score5)
highest = score2;
if (score3 > score1 && score3 > score2 && score3 > score4 && score3 > score5)
highest = score3;
if (score4 > score1 && score4 > score2 && score4 > score3 && score4 > score5)
highest = score4;
if (score5 > score1 && score5 > score2 && score5 > score3 && score5 > score4)
highest = score5;
return highest;
}
double findLowest()
{
double score1, score2, score3, score4, score5;
double lowest = 0;
if (score1 < score2 && score1 < score3 && score1 < score4 && score1 < score5)
lowest = score1;
if (score2 < score1 && score2 < score3 && score2 < score4 && score2 < score5)
lowest = score2;
if (score3 < score1 && score3 < score2 && score3 < score4 && score3 < score5)
lowest = score3;
if (score4 < score1 && score4 < score2 && score4 < score3 && score4 < score5)
lowest = score4;
if (score5 < score1 && score5 < score2 && score5 < score3 && score5 < score4)
lowest = score5;
return lowest;
}
void calcScore()
{
double score1, score2, score3, score4, score5;
double lowest;
double highest;
double findHighest(highest);
double findLowest(lowest);
double totalScore;
double avgScore;
totalScore = score1 + score2 + score3 + score4 + score5;
avgScore = (totalScore - (highest+lowest))/3;
cout << "\nThe contestant's average score is: " << avgScore << endl;
}
int main() {
double score1, score2, score3, score4, score5;
double lowest, highest;
getJudgeData1(score1);
getJudgeData2(score2);
getJudgeData3(score3);
getJudgeData4(score4);
getJudgeData5(score5);
calcScore();
system("PAUSE");
return 0;
}
|