//02/2008 //Welcome to my program, allows user to enter 5 scores from 5 judges, then //averages 3 scores, excluding the highest and lowest score //validates each score entered by user for number between 0 and 10 #include #include using namespace std; void getJudgeData(double&, double&, double&, double&, double&); void calcScore(double&); int findLowest(double&); int findHighest(double&); double score1, score2, score3, score4, score5, LowestScore, HighestScore; double TotalScore; int main() { cout << endl; cout <<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"; cout <<"+++++++++Welcome to My Star Search Score Averaging Program.++++++++++\n"; cout <<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"; cout <<"This program will ask for 5 scores, one from each judge. It will\n"; cout <<"drop the highest and lowest score, and average the other 3.\n"; cout <<"---------------------------------------------------------------------\n"; getJudgeData(score1, score2, score3, score4, score5); calcScore(TotalScore); return 0; } //*********************************************************************** //definition of getJudgeData //will store judge scores in score1,score2,score3,score4,score5 //validates each score for int between 0-10 //*********************************************************************** void getJudgeData(double &score1, double &score2, double &score3, double &score4, double &score5) { cout << "Enter score from Judge #1 (must be from 0-10): "; cin >> score1; while (score1 <0 || score1 > 10) { cout <<"Score is only valid from 0-10, try again: "; cin >> score1; } cout << "Enter score from Judge #2 (must be from 0-10): "; cin >> score2; while (score2 <0 || score2 > 10) { cout <<"Score is only valid from 0-10, try again: "; cin >> score2; } cout << "Enter score from Judge #3 (must be from 0-10): "; cin >> score3; while (score3 <0 || score3 > 10) { cout <<"Score is only valid from 0-10, try again: "; cin >> score3; } cout << "Enter score from Judge #4 (must be from 0-10): "; cin >> score4; while (score4 <0 || score4 > 10) { cout <<"Score is only valid from 0-10, try again: "; cin >> score4; } cout << "Enter score from Judge #5 (must be from 0-10): "; cin >> score5; while (score5 <0 || score5 > 10) { cout <<"Score is only valid from 0-10, try again: "; cin >> score5; } } //*********************************************************************** //definition of findLowest() //function to find lowest score //return LowestScore to use in main //*********************************************************************** int findLowest(double &LowestScore) { //cout <=score2 && score1>=score3 && score1>=score4 && score1>=score5) HighestScore=score1; else if (score2>=score1 && score2>=score3 && score2>=score4 && score2>=score5) HighestScore=score2; else if (score3>=score1 && score3>=score2 && score3>=score4 && score3>=score5) HighestScore=score3; else if (score4>=score1 && score4>=score2 && score4>=score3 && score4>=score5) HighestScore=score4; else if (score5>=score1 && score5>=score2 && score5>=score3 && score5>=score4) HighestScore=score5; cout <<"---------------------------------------------------------------------\n"; cout <<"The highest score is " << fixed << setprecision(1) << HighestScore << " and will not be considered in average." << endl; return 0; } //*********************************************************************** //definition of calcScore() //function to add all scores and subtract highest and lowest //then divide by 3 for average score //*********************************************************************** void calcScore(double &TotalScore) { findLowest(LowestScore); findHighest(HighestScore); TotalScore = (((score1+score2+score3+score4+score5)-(LowestScore+HighestScore))/3); cout <<"---------------------------------------------------------------------\n"; cout <<"The average score is determined by dropping the highest and lowest\n"; cout <<"score and averaging the three remaining scores.\n"; cout <<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"; cout <<"The average score is " << fixed << setprecision(2) << TotalScore << " for this Star." << endl; cout <<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"; }