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
|
//The purpose of this program was to ask the user to input 5 scores using
//functions to find the lowest and highest scores, and then dropping them
//to have only three left, averaging them and then display the results.
#include <iostream>
using namespace std;
//Function Prototypes
double getJudgeData(); //Function for inputing values and validating that theyr'e in range.
double findLowest(); //Finds the lowest score and returns value for later use.
double findHighest(); //Finds the highest score and returns value for later use.
double calcScore(); //Uses and calculates returned values for average score.
//Main Function and displays functions' results.
int main()
{
double lowestScore, highestScore, totalScore;
getJudgeData();
lowestScore = findLowest();
highestScore = findHighest();
totalScore = calcScore();
cout<<"The contestant's total score is: "<<totalScore<<endl;
return 0;
}
//Function for user input.
double getJudgeData()
{
double score1, score2, score3, score4, score5, total;
cout<<"Please enter your rating."<<endl;
cin>>score1>>score2>>score3>>score4>>score5;
//It validates that the numbers are within range.
while(score1 < 0 || score1 > 10)
{
cout<<"Invalid number, enter a rating between 0 through 10 only."<<endl;
cin>>score1;
}
while(score2 < 0 || score2 > 10)
{
cout<<"Invalid number, enter a rating between 0 through 10 only."<<endl;
cin>>score2;
}
while(score3 < 0 || score3 > 10)
{
cout<<"Invalid number, enter a rating between 0 through 10 only."<<endl;
cin>>score3;
}
while(score4 < 0 || score4 > 10)
{
cout<<"Invalid number, enter a rating between 0 through 10 only."<<endl;
cin>>score4;
}
while(score5 < 0 || score5 > 10)
{
cout<<"Invalid number, enter a rating between 0 through 10 only."<<endl;
cin>>score5;
}
total = score1 + score2 + score3 + score4 + score5;
return total;
} //Return? (Trying to return score1-score5 but don't know how. Total as temp.)
//This function is to find the lowest score and return the value.
double findLowest(double score1, double score2, double score3, double score4, double score5)
{
double lowestScore, total;
if(score1 <= score2 && score1 <= score3 && score1 <= score4 && score1 <= score5)
{
lowestScore = score1;
}
else if(score2 <= score1 && score2 <= score3 && score2 <= score4 && score2 <= score5)
{
lowestScore = score2;
}
else if(score3 <= score1 && score3 <= score2 && score3 <= score4 && score3 <= score5)
{
lowestScore = score3;
}
else if(score4 <= score1 && score4 <= score2 && score4 <= score3 && score4 <= score5)
{
lowestScore = score5;
}
else if(score5 <= score1 && score5 <= score2 && score5 <= score3 && score5 <= score4)
{
lowestScore = score5;
}
return lowestScore;
}
//This function is to find the highest score, and returns the value.
double findHighest(double score1, double score2, double score3, double score4, double score5)
{
double highestScore;
if(score1 >= score2 && score1 >= score3 && score1 >= score4 && score1 >= score5)
{
highestScore = score1;
}
if(score2 >= score1 && score2 >= score3 && score2 >= score4 && score2 >= score5)
{
highestScore = score2;
}
if(score3 >= score1 && score3 >= score2 && score3 >= score4 && score3 >= score5)
{
highestScore = score3;
}
if(score4 >= score1 && score4 >= score2 && score4 >= score3 && score4 >= score5)
{
highestScore = score4;
}
if(score5 >= score1 && score5 >= score2 && score5 >= score3 && score5 >= score4)
{
highestScore = score5;
}
return highestScore;
}
//Function to drop highest and lowest scores and average out the total score. Then returns value to main.
double calcScore(double total, double lowestScore, double highestScore)
{
double totalScore;
totalScore = (total - (lowestScore + highestScore)) / 3;
return totalScore;
}
|