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
|
#include <iostream>
using namespace std;
void getJudgeData(int &);
void calcScore(int, int, int, int, int);
int findLowest(int, int, int, int, int);
int findHighest(int, int, int, int, int);
int main()
{
int score1, score2, score3, score4, score5;
cout << " Judge 1: " << endl;
getJudgeData(score1);
cout << "\n Judge 2: " << endl;
getJudgeData(score2);
cout << "\n Judge 3: " << endl;
getJudgeData(score3);
cout << "\n Judge 4: " << endl;
getJudgeData(score4);
cout << "\n Judge 5: " << endl;
getJudgeData(score5);
calcScore(score1, score2, score3, score4, score5);
}
void getJudgeData(int &refVar)
{
cout << " What is the judge's score? ";
cin >> refVar;
while(refVar < 0 || refVar > 10)
{
cout << " The Judge cannot give a score lower than 0, or higher than 10.\n";
cout << " What is the Judge's score? ";
cin >> refVar;
}
}
void calcScore(int score_1, int score_2, int score_3, int score_4, int score_5)
{
cout << "\n The highest and lowest scores will be dropped." << endl;
findLowest(score_1, score_2, score_3, score_4, score_5);
findHighest(score_1, score_2, score_3, score_4, score_5);
cout << "\n The remaining scores will be averaged. " << endl;
}
int findLowest(int num1, int num2, int num3, int num4, int num5)
{
if(num1 < num2 && num1 < num3 && num1 < num4 && num1 < num5)
{
cout << " The lowest Judge score is " << num1 << endl;
return num1;
}
else if(num2 < num3 && num2 < num4 && num2 < num5 && num2 < num1)
{
cout << " The lowest Judge score is " << num2 << endl;
return num2;
}
else if(num3 < num4 && num3 < num5 && num3 < num1 && num3 < num2)
{
cout << " The lowest Judge score is " << num3 << endl;
return num3;
}
else if(num4 < num5 && num4 < num1 && num4 < num2 && num4 < num3)
{
cout << " The lowest Judge score is " << num4 << endl;
return num4;
}
else if(num5 < num1 && num5 < num2 && num5 < num3 && num5 < num4)
{
cout << " The lowest Judge score is " << num5 << endl;
return num5;
}
return 0;
}
int findHighest(int num1, int num2, int num3, int num4, int num5)
{
if(num1 > num2 && num1 > num3 && num1 > num4 && num1 > num5)
{
cout << " The highest Judge score is " << num1 << endl;
return num1;
}
else if(num2 > num3 && num2 > num4 && num2 > num5 && num2 > num1)
{
cout << " The highest Judge score is " << num2 << endl;
return num2;
}
else if(num3 > num4 && num3 > num5 && num3 > num1 && num3 > num2)
{
cout << " The highest Judge score is " << num3 << endl;
return num3;
}
else if(num4 > num5 && num4 > num1 && num4 > num2 && num4 > num3)
{
cout << " The highest Judge score is " << num4 << endl;
return num4;
}
else if(num5 > num1 && num5 > num2 && num5 > num3 && num5 > num4)
{
cout << " The highest Judge score is " << num5 << endl;
return num5;
}
return 0;
}
|