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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
#include <iostream>
#include <iomanip>
using namespace std;
void getJudgeData(double &score);
//prototype for judge function
void calcScore(double s1, double s2, double s3, double s4, double s5);
//prototype to calculate average
double findLowest(double s1, double s2, double s3, double s4, double s5);
//protype to find lowest score
double findHighest(double s1, double s2, double s3, double s4, double s5);
//protype to find highest score
int main ()
{
int contestant = 1;
double score = 0;
char yesNo = 'n'; //defines variable yesNo
do
{
cout << "\nwelcome to star search" << "\n" << "----------------------" << endl; //introduction to program
cout << "contestant #" << contestant << "\n" << endl;
getJudgeData(score); // calls to function getJudgeData
cout << "would you like to enter another contestant? (Y/N)" << endl;
cin >> yesNo;
contestant++; //inrements contestant
} while (yesNo == 'y' || yesNo == 'Y'); //creates parameter
system("pause");
return 0;
}
void getJudgeData(double &score)
{
double score1, score2, score3, score4, score5 = 0; //declares scores
cout << "*****judge1*****" << endl;
cout << "enter a score: (1-10)" << endl;
cin >> score1;
while (score1 < 0 || score1 >10) // prevents scores less than zero and more than ten
{
cout << "please enter a valid number: (1-10)" << endl;
cin >> score1;
}
cout << "\n*****judge2*****" << endl; // repeats for every judge
cout << "enter a score: (1-10)" << endl;
cin >> score2;
while (score2 < 0 || score2 >10)
{
cout << "please enter a valid number: (1-10)" << endl;
cin >> score2;
}
cout << "\n*****judge3*****" << endl;
cout << "enter a score: (1-10)" << endl;
cin >> score3;
while (score3 < 0 || score3 >10)
{
cout << "please enter a valid number: (1-10)" << endl;
cin >> score3;
}
cout << "\n*****judge4*****" << endl;
cout << "enter a score: (1-10)" << endl;
cin >> score4;
while (score4 < 0 || score4 >10)
{
cout << "please enter a valid number: (1-10)" << endl;
cin >> score4;
}
cout << "\n*****judge5*****" << endl;
cout << "enter a score: (1-10)" << endl;
cin >> score5;
while (score5 < 0 || score5 >10)
{
cout << "please enter a valid number: (1-10)" << endl;
cin >> score5;
}
findHighest(score1, score1, score3, score4, score5); //calls findHighest function
findLowest (score1, score1, score3, score4, score5); //calls findLowest function
cout << "\nhighest score is: " << findHighest << endl; //shows highest
cout << "lowest score is: " << findLowest << endl; //shows lowest
calcScore(score1, score1, score3, score4, score5); //calls to calcScore
}
void calcScore(double s1, double s2, double s3, double s4, double s5) //finds the final score
{
double score1 = s1;
double score2 = s2;
double score3 = s3;
double score4 = s4;
double score5 = s5;
double highest = findHighest(score1, score1, score3, score4, score5); // calls to findHighest
double lowest = findLowest(score1, score1, score3, score4, score5); // calls to findLowest
double scoresAdded = (score1 + score2 + score3 + score4 + score5); // adds the scores
double finalScore = (scoresAdded - highest - lowest)/3; // finds the average after cutting the highest and lowest scores
cout << "\nthe final score is: " << calcScore << endl << endl; // shows final score
}
double findLowest(double s1, double s2, double s3, double s4, double s5) //finds the min
{
double lowest = 0; // declares lowest as min
if (s1 < s2 && s1 < s3 && s1 < s4 && s1 < s5) //declares s1 as min
{
lowest = s1;
}
if (s2 < s1 && s2 < s3 && s2 < s4 && s2 < s5) // s2 as min
{
lowest = s2;
}
if (s3 < s2 && s3 < s1 && s3 < s4 && s3 < s5) // s3 as min
{
lowest = s3;
}
if (s4 < s2 && s4 < s3 && s4 < s1 && s4 < s5) // s4 as min
{
lowest = s4;
}
if (s5 < s2 && s5 < s3 && s5 < s4 && s5 < s1) // s5 as min
{
lowest = s5;
}
return lowest; // returns lowest as the value of findLowest
}
double findHighest(double s1, double s2, double s3, double s4, double s5) //finds max
{
double highest = 0; //declares highest as max
if (s1 > s2 && s1 > s3 && s1 > s4 && s1 >s5 ) //declares s1 as max
{
highest = s1;
}
if (s2 > s1 && s2 > s3 && s2 > s4 && s2 >s5) // s2 as max
{
highest = s2;
}
if (s3 > s2 && s3 > s1 && s3 > s4 && s3 >s5) // s3 as max
{
highest = s3;
}
if (s4 > s2 && s4 > s3 && s4 > s1 && s4 >s5) // s4 as max
{
highest = s4;
}
if (s5 > s2 && s5 > s3 && s5 > s4 && s5 >s1) // and s5 as max
{
highest = s5;
}
return highest; //returns highest as the value of findHighest
}
|