Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- A particular talent competition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed.
- A performer's final score is determined by dropping the highest and lowest score received, then averaging the 3 remaining scores.
- Write a program that uses this method to calculate a contestant's score. It should include the following functions:
- void getJudgeData() -- This should ask the user for a judge's score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the 5 judges.
- void calcScore() -- This should calculate and display the average of the 3 scores that remain after dropping the highest and lowest scores the performer received.
- This function should be called just once by main, and should be passed the 5 scores.
- The last two functions, described below, should be called by calcScore, which uses the returned information to determine which of the scores to drop.
- int findLowest() -- This should find and return the lowest of the 5 scores passed to it.
- int findHighest() -- This should find and return the highest of the 5 scores passed to it.
- Finally, Input Validation: Do not accept judge scores lower than 0 or higher than 10.
- Program File : Ch6_8.cpp
- Program Name : Star Search
- Program Description : This program will take scores from 5 different judges and average out the three middle ones to give contestants
- their scores
- Created by : Ryan Lawler
- Last Edited : October 27, 2014
- */
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <cmath>
- using namespace std;
- // Functions
- double getJudgeData(double& score1, double& score2, double& score3, double& score4, double& score5);
- double findLowest(double &lowestScore);
- double findHighest(double &highestScore);
- double calcScore(double &score1, double& score2, double& score3, double& score4, double& score5);
- // Variables
- double score1;
- double score2;
- double score3;
- double score4;
- double score5;
- double lowestScore;
- double highestScore;
- double judgeTotal;
- int main()
- {
- double getJudgeData(double &, double &, double &, double &, double &);
- // Call getJudgeData to get a number and store
- getJudgeData(score1, score2, score3, score4, score5);
- cout << "\nJudges scores are :\n" << score1 << endl;
- cout << score2 << endl;
- cout << score3 << endl;
- cout << score4 << endl;
- cout << score5 << endl;
- system("Pause");
- findLowest(lowestScore);
- findLowest(highestScore);
- // Call judgeTotal
- double calcScore(double &judgeTotal);
- cout << endl << lowestScore << endl;
- cout << endl << highestScore << endl;
- cout << "\nAverage is " << judgeTotal << endl << endl;
- system("Pause");
- }
- double getJudgeData(double& score1, double& score2, double& score3, double& score4, double& score5)
- {
- cout << "Enter the Scores for Judge 1.\n\n";
- cin >> score1;
- cout << endl;
- if (score1 < 0 || score1 > 10)
- {
- cout << "That Score is Invalid.\n\n" << "Please enter a number between 0 and 10.\n\n";
- cin >> score1;
- }
- else if (score1 >= 0 && score1 <= 5)
- {
- cout << "Better Luck Next Time!\n\n" << endl;
- }
- else if (score1 <= 10 && score1 > 5)
- cout << "Great Job!\n\n";
- cout << "\nEnter the Scores for Judge 2.\n\n";
- cin >> score2;
- cout << endl;
- if (score2 < 0 || score2 > 10)
- {
- cout << "That Score is Invalid.\n\n" << "Please enter a number between 0 and 10.\n\n";
- cin >> score2;
- }
- else if (score2 >= 0 && score2 <= 5)
- {
- cout << "Better Luck Next Time!\n\n" << endl;
- }
- else if (score2 <= 10 && score2 > 5)
- cout << "Great Job!\n\n" << endl;
- cout << "Enter the Scores for Judge 3.\n\n";
- cin >> score3;
- cout << endl;
- if (score3 < 0 || score3 > 10)
- {
- cout << "That Score is Invalid.\n\n" << "Please enter a number between 0 and 10.\n\n";
- cin >> score3;
- }
- else if (score3 >= 0 && score3 <= 5)
- {
- cout << "Better Luck Next Time!\n\n" << endl;
- }
- else if (score3 <= 10 && score3 > 5)
- cout << "Great Job!\n\n" << endl;
- cout << "Enter the Scores for Judge 4.\n\n";
- cin >> score4;
- cout << endl;
- if (score4 < 0 || score4 > 10)
- {
- cout << "That Score is Invalid.\n\n" << "Please enter a number between 0 and 10.\n\n";
- cin >> score4;
- }
- else if (score4 >= 0 && score4 <= 5)
- {
- cout << "Better Luck Next Time!\n\n" << endl;
- }
- else if (score4 <= 10 && score4 > 5)
- cout << "Great Job!\n\n" << endl;
- cout << "Enter the Scores for Judge 5.\n\n";
- cin >> score5;
- cout << endl;
- if (score5 < 0 || score5 > 10)
- {
- cout << "That Score is Invalid.\n\n" << "Please enter a number between 0 and 10.\n\n";
- cin >> score5;
- }
- else if (score5 >= 0 && score5 <= 5)
- {
- cout << "Better Luck Next Time!\n\n" << endl;
- }
- else if (score5 <= 10 && score5 > 5)
- cout << "Great Job!\n\n" << endl;
- system("Pause");
- return score1, score2, score3, score4, score5;
- }
- double findLowest(double &lowestScore)
- {
- 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 = score4;
- else if ((score5 <= score1) && (score5 <= score2) && (score5 <= score3) && (score5 <= score4))
- lowestScore = score5;
- return lowestScore;
- }
- double findHighest(double &highestScore)
- {
- if ((score1 >= 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;
- return highestScore;
- }
- double calcScore(double &score1, double &score2, double &score3, double &score4, double &score5)
- {
- double totalScore;
- double findLowest(double &);
- double findHighest(double &);
- findHighest(highestScore);
- findLowest(lowestScore);
- judgeTotal = (((score1 + score2 + score3 + score4 + score5) - (highestScore + lowestScore)) / 3);
- return judgeTotal;
- }
Advertisement
Add Comment
Please, Sign In to add comment