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
|
#include <iostream>
#include <cmath>
using namespace std;
// Prototype
void get_data(float &score);
void calcScore (float &averageScore, float judge1, float judge2, float judge3, float judge4, float judge5);
int findHighest (float judge1, float judge2, float judge3, float judge4, float judge5);
int findLowest (float judge1, float judge2, float judge3, float judge4, float judge5);
// Calculate The Final Average
void calcScore (float&averageScore, float judge1, float judge2, float judge3, float judge4, float judge5)
{
float lowest;
float highest;
float removedHighLow;
float totalScore;
totalScore = judge1 + judge2 + judge3 + judge4 + judge5;
// Get the lowest score plugged into a variable
lowest = findLowest (judge1, judge2, judge3, judge4, judge5);
// Get the highest score plugged into a variable
highest = findHighest (judge1, judge2, judge3, judge4, judge5);
// Drop the highest and lowest scores
removedHighLow = totalScore - (lowest + highest);
// Obtain the average of the three scores
averageScore = removedHighLow / 3;
}
// Find the highest value.
int findHighest (float judge1, float judge2, float judge3, float judge4, float judge5)
{
if (judge1 > judge2 && judge1 > judge3 && judge1 > judge4 && judge1 > judge5)
return judge1;
else if (judge2 > judge1 && judge2 > judge3 && judge2 > judge4 && judge2 > judge5)
return judge2;
else if (judge3 > judge1 && judge3 > judge2 && judge3 > judge4 && judge3 > judge5)
return judge3;
else if (judge4 > judge1 && judge4 > judge2 && judge4 > judge3 && judge4 > judge5)
return judge4;
else
return judge5;
}
// Find the lowest value.
int findLowest (float judge1, float judge2, float judge3, float judge4, float judge5)
{
if (judge1 < judge2 && judge1 < judge3 && judge1 < judge4 && judge1 < judge5)
return judge1;
else if (judge2 < judge1 && judge2 < judge3 && judge2 < judge4 && judge2 < judge5)
return judge2;
else if (judge3 < judge1 && judge3 < judge2 && judge3 < judge4 && judge3 < judge5)
return judge3;
else if (judge4 < judge1 && judge4 < judge2 && judge4 < judge3 && judge4 < judge5)
return judge4;
else
return judge5;
}
int main()
{
float averageScore;
float judge1;
// Actual call
get_data(judge1);
float judge2;
// Actual call
get_data(judge2);
float judge3;
// Actual call
get_data(judge3);
float judge4;
// Actual call
get_data(judge4);
float judge5;
// Actual call
get_data(judge5);
calcScore (averageScore, judge1, judge2, judge3, judge4, judge5);
cout << "The average score for this performer is " << averageScore << " points!" << endl;
}
// Formal Function Heading & Details
void get_data (float &score)
{
cout << "Please enter a score: ";
cin >> score;
while (score > 10.0 || score < 0.0)
{
cout << "ERROR: Please enter a judge's score between '0' and '10': ";
cin >> score;
}
}
|