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
|
//This program takes five scores, drops the highest and lowest score, then
// provides the average of the three remaining scores.
#include <iostream>
#include <iomanip>
using namespace std;
void getJudgeData (double &); //prototype for function getJudgeData
void calcScore (double, double, double, double, double); //prototype for function calcScore
double findLowest (double, double, double, double, double); //prototype for function findLowest
double findHighest (double, double, double, double, double); //prototype for function findHighest
int main ()
{
double judge1, judge2, judge3, judge4, judge5; //variables to hold judges scores
getJudgeData (judge1); //function call passing ref variable
getJudgeData (judge2); //function call passing ref variable
getJudgeData (judge3); //function call passing ref variable
getJudgeData (judge4); //function call passing ref variable
getJudgeData (judge5); //function call passing ref variable
calcScore (judge1, judge2, judge3, judge4, judge5); //function call passing judges scores
return 0;
}
//*******************************************************
//Function definition - This function asks for the *
//judges score and validates user input, then changes *
//the judge variable. *
//*******************************************************
void getJudgeData (double &refJudge)
{
cout << "Enter the judges score: \n";
cin >> refJudge;
while (refJudge < 0 || refJudge > 10)
{
cout << "Error! Enter a number between 0 and 10: \n";
cin >> refJudge;
}
}
//*******************************************************
// Function definition - Function calcScore claculates *
// the average score after the lowest and highest score *
//has been dropped. *
//*******************************************************
void calcScore (double j1, double j2, double j3, double j4, double j5)
{
double average;
double low = findLowest (j1, j2, j3, j4, j5);
double high = findHighest (j1, j2, j3, j4, j5);
average = ((j1 + j2 + j3 + j4 + j5) - (low + high))/3;
cout << fixed << showpoint << setprecision(1);
cout << "Average Score : " << average << endl;
}
//*******************************************************
//Function definition - Function findLowest finds the *
// lowest score and returns lowest to calScore. *
//*******************************************************
double findLowest (double s1, double s2, double s3, double s4, double s5)
{
double lowest;
if ( s1 < s2 && s1 < s3 && s1 < s4 && s1 < s5)
lowest = s1;
else if ( s2 < s1 && s2 < s3 && s2 < s4 && s2 < s5)
lowest = s2;
else if ( s3 < s1 && s3 < s2 && s3 < s4 && s3 < s5)
lowest = s3;
else if ( s4 < s1 && s4 < s2 && s4 < s3 && s4 < s5)
lowest = s4;
else
lowest = s5;
return lowest;
}
//*******************************************************
//Function definition - Function findHighest finds the *
//highest score and returns highest to calcScore. *
//*******************************************************
double findHighest (double s1, double s2, double s3, double s4, double s5)
{
double highest;
if ( s1 > s2 && s1 > s3 && s1 > s4 && s1 > s5)
highest = s1;
else if ( s2 > s1 && s2 > s3 && s2 > s4 && s2 > s5)
highest = s2;
else if ( s3 > s1 && s3 > s2 && s3 > s4 && s3 > s5)
highest = s3;
else if ( s4 > s1 && s4 > s2 && s4 > s3 && s4 > s5)
highest = s4;
else
highest = s5;
return highest;
}
| |