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
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int score(int judgesScore) //function to input score
{
cout << "Please enter the judge's score: " << endl; //asks user to input score
cin >> judgesScore; //input score
do
{if ((judgesScore > 10) || (judgesScore < 0)) //if the score is not between 0 and 10,
{
cout << "The score must be between 0 and 10. Please enter the judge's score: " << endl; //output that the score must be between 0 and 10
cin >> judgesScore; //and input a new score
}
}while ((judgesScore > 10) || (judgesScore < 0)); //loop until a score between 0 and 10 is entered
return judgesScore; //return judge's score
}
int findlowest(int score1, int score2, int score3, int score4, int score5, int lowest) //function to find lowest score
{
if (score1 < score2 && score1 < score3 && score1 < score4 && score1 < score5) //if score1 is the lowest,
{
lowest = score1; //add its value to lowest
}
if (score2 < score1 && score2 < score3 && score2 < score4 && score2 < score5) //if score2 is the lowest,
{
lowest = score2; //add its value to lowest
}
if (score3 < score1 && score3 < score2 && score3 < score4 && score3 < score5) //if score3 is the lowest,
{
lowest = score3; //add its value to lowest
}
if (score4 < score1 && score4 < score2 && score4 < score3 && score4 < score5) //if score4 is the lowest,
{
lowest = score4; //add its value to lowest
}
if (score5 < score1 && score5 < score2 && score5 < score3 && score5 < score4) //if score5 is the lowest,
{
lowest = score5; //add its value to lowest
}
return lowest;
}
int findhighest(int score1, int score2, int score3, int score4, int score5, int highest) //function to find the highest score
{
if (score1 > score2 && score1 > score3 && score1 > score4 && score1 > score5) //if score1 is the highest,
{
highest = score1; //add its value to highest
}
if (score2 > score1 && score2 > score3 && score2 > score4 && score2 > score5) //if score2 is the highest,
{
highest = score2; //add its value to highest
}
if (score3 > score1 && score3 > score2 && score3 > score4 && score3 > score5) //if score3 is the highest,
{
highest = score3; //add its value to highest
}
if (score4 > score1 && score4 > score2 && score4 > score3 && score4 > score5) //if score4 is the highest,
{
highest = score4; //add its value to highest
}
if (score5 < score1 && score5 < score2 && score5 < score3 && score5 < score4) //if score5 is the highest,
{
highest = score5; //add its value to highest
}
return highest;
}
int calcscore(int score1, int score2, int score3, int score4, int score5, int overallScore, int lowest, int highest)
{
findlowest(score1, score2, score3, score4, score5, lowest); //call findlowest function to find the lowest score
findhighest(score1, score2, score3, score4, score5, highest); //call findhighest function to find the highest score
overallScore = ((score1 + score2 + score3 + score4 + score5 - lowest - highest)/3); //calculate the average of the scores, after dropping the highest and lowest
cout << "This contestant's overall score is " << overallScore << endl; //output the final score
return 0;
}
int main(int judgesScore, int score1, int score2, int score3, int score4, int score5, int overallScore, int lowest, int highest)
{
score(judgesScore); //call score function for the first judge's score
score1 = judgesScore; //set score1 as the first judge's score
score(judgesScore); //call score function for the second judge's score
score2 = judgesScore; //set score2 as the second judge's score
score(judgesScore); //call score function for the third judge's score
score3 = judgesScore; //set score3 as the third judge's score
score(judgesScore); //call score function for the fourth judge's score
score4 = judgesScore; //set score4 as fourth judge's score
score(judgesScore); //call score function for the fifth judge's score
score5 = judgesScore; //set score5 as fifth judge's score
calcscore(score1, score2, score3, score4, score5, overallScore, lowest, highest); //call calcscore function to get the final score
system("pause"); //pause program to keep it open
}
|