Lawlzes

C++ Ch6_8.cpp

Oct 27th, 2014
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. /*
  2. 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.
  3. A performer's final score is determined by dropping the highest and lowest score received, then averaging the 3 remaining scores.
  4. Write a program that uses this method to calculate a contestant's score. It should include the following functions:
  5. 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.
  6. 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.
  7. This function should be called just once by main, and should be passed the 5 scores.
  8. The last two functions, described below, should be called by calcScore, which uses the returned information to determine which of the scores to drop.
  9. int findLowest() -- This should find and return the lowest of the 5 scores passed to it.
  10. int findHighest() -- This should find and return the highest of the 5 scores passed to it.
  11. Finally, Input Validation: Do not accept judge scores lower than 0 or higher than 10.
  12.  
  13. Program File : Ch6_8.cpp
  14. Program Name : Star Search
  15. Program Description : This program will take scores from 5 different judges and average out the three middle ones to give contestants
  16. their scores
  17. Created by : Ryan Lawler
  18. Last Edited : October 27, 2014
  19. */
  20.  
  21. #include <iostream>
  22. #include <iomanip>
  23. #include <fstream>
  24. #include <cmath>
  25.  
  26. using namespace std;
  27.  
  28. // Functions
  29.  
  30. double getJudgeData(double& score1, double& score2, double& score3, double& score4, double& score5);
  31. double findLowest(double &lowestScore);
  32. double findHighest(double &highestScore);
  33. double calcScore(double &score1, double& score2, double& score3, double& score4, double& score5);
  34.  
  35. // Variables
  36.  
  37. double score1;
  38. double score2;
  39. double score3;
  40. double score4;
  41. double score5;
  42. double lowestScore;
  43. double highestScore;
  44. double judgeTotal;
  45.  
  46. int main()
  47. {
  48.  
  49. double getJudgeData(double &, double &, double &, double &, double &);
  50.  
  51. // Call getJudgeData to get a number and store
  52.  
  53. getJudgeData(score1, score2, score3, score4, score5);
  54.  
  55. cout << "\nJudges scores are :\n" << score1 << endl;
  56. cout << score2 << endl;
  57. cout << score3 << endl;
  58. cout << score4 << endl;
  59. cout << score5 << endl;
  60.  
  61. system("Pause");
  62.  
  63. findLowest(lowestScore);
  64. findLowest(highestScore);
  65. // Call judgeTotal
  66.  
  67. double calcScore(double &judgeTotal);
  68.  
  69. cout << endl << lowestScore << endl;
  70. cout << endl << highestScore << endl;
  71.  
  72. cout << "\nAverage is " << judgeTotal << endl << endl;
  73.  
  74. system("Pause");
  75. }
  76.  
  77. double getJudgeData(double& score1, double& score2, double& score3, double& score4, double& score5)
  78.  
  79. {
  80.  
  81.  
  82. cout << "Enter the Scores for Judge 1.\n\n";
  83. cin >> score1;
  84. cout << endl;
  85.  
  86.  
  87. if (score1 < 0 || score1 > 10)
  88. {
  89.  
  90. cout << "That Score is Invalid.\n\n" << "Please enter a number between 0 and 10.\n\n";
  91. cin >> score1;
  92.  
  93. }
  94. else if (score1 >= 0 && score1 <= 5)
  95. {
  96.  
  97. cout << "Better Luck Next Time!\n\n" << endl;
  98.  
  99. }
  100. else if (score1 <= 10 && score1 > 5)
  101.  
  102. cout << "Great Job!\n\n";
  103.  
  104.  
  105.  
  106. cout << "\nEnter the Scores for Judge 2.\n\n";
  107. cin >> score2;
  108. cout << endl;
  109.  
  110. if (score2 < 0 || score2 > 10)
  111. {
  112. cout << "That Score is Invalid.\n\n" << "Please enter a number between 0 and 10.\n\n";
  113. cin >> score2;
  114.  
  115. }
  116. else if (score2 >= 0 && score2 <= 5)
  117. {
  118.  
  119. cout << "Better Luck Next Time!\n\n" << endl;
  120.  
  121. }
  122. else if (score2 <= 10 && score2 > 5)
  123.  
  124. cout << "Great Job!\n\n" << endl;
  125.  
  126.  
  127.  
  128. cout << "Enter the Scores for Judge 3.\n\n";
  129. cin >> score3;
  130. cout << endl;
  131.  
  132. if (score3 < 0 || score3 > 10)
  133. {
  134. cout << "That Score is Invalid.\n\n" << "Please enter a number between 0 and 10.\n\n";
  135. cin >> score3;
  136.  
  137. }
  138. else if (score3 >= 0 && score3 <= 5)
  139. {
  140.  
  141. cout << "Better Luck Next Time!\n\n" << endl;
  142.  
  143. }
  144. else if (score3 <= 10 && score3 > 5)
  145.  
  146. cout << "Great Job!\n\n" << endl;
  147.  
  148.  
  149. cout << "Enter the Scores for Judge 4.\n\n";
  150. cin >> score4;
  151. cout << endl;
  152.  
  153. if (score4 < 0 || score4 > 10)
  154. {
  155. cout << "That Score is Invalid.\n\n" << "Please enter a number between 0 and 10.\n\n";
  156. cin >> score4;
  157.  
  158. }
  159. else if (score4 >= 0 && score4 <= 5)
  160. {
  161.  
  162. cout << "Better Luck Next Time!\n\n" << endl;
  163.  
  164. }
  165. else if (score4 <= 10 && score4 > 5)
  166.  
  167. cout << "Great Job!\n\n" << endl;
  168.  
  169.  
  170. cout << "Enter the Scores for Judge 5.\n\n";
  171. cin >> score5;
  172. cout << endl;
  173.  
  174. if (score5 < 0 || score5 > 10)
  175. {
  176. cout << "That Score is Invalid.\n\n" << "Please enter a number between 0 and 10.\n\n";
  177. cin >> score5;
  178.  
  179. }
  180. else if (score5 >= 0 && score5 <= 5)
  181. {
  182.  
  183. cout << "Better Luck Next Time!\n\n" << endl;
  184.  
  185. }
  186. else if (score5 <= 10 && score5 > 5)
  187.  
  188. cout << "Great Job!\n\n" << endl;
  189.  
  190. system("Pause");
  191.  
  192. return score1, score2, score3, score4, score5;
  193. }
  194.  
  195.  
  196. double findLowest(double &lowestScore)
  197.  
  198. {
  199.  
  200.  
  201. if ((score1 <= score2) && (score1 <= score3) && (score1 <= score4) && (score1 <= score5))
  202. lowestScore = score1;
  203.  
  204. else if ((score2 <= score1) && (score2 <= score3) && (score2 <= score4) && (score2 <= score5))
  205. lowestScore = score2;
  206.  
  207. else if ((score3 <= score1) && (score3 <= score2) && (score3 <= score4) && (score3 <= score5))
  208. lowestScore = score3;
  209.  
  210. else if ((score4 <= score1) && (score4 <= score2) && (score4 <= score3) && (score4 <= score5))
  211. lowestScore = score4;
  212.  
  213. else if ((score5 <= score1) && (score5 <= score2) && (score5 <= score3) && (score5 <= score4))
  214. lowestScore = score5;
  215.  
  216. return lowestScore;
  217. }
  218.  
  219. double findHighest(double &highestScore)
  220.  
  221. {
  222.  
  223.  
  224. if ((score1 >= score2) && (score1 >= score3) && (score1 >= score4) && (score1 >= score5))
  225. highestScore = score1;
  226.  
  227. else if ((score2 >= score1) && (score2 >= score3) && (score2 >= score4) && (score2 >= score5))
  228. highestScore = score2;
  229.  
  230. else if ((score3 >= score1) && (score3 >= score2) && (score3 >= score4) && (score3 >= score5))
  231. highestScore = score3;
  232.  
  233. else if ((score4 >= score1) && (score4 >= score2) && (score4 >= score3) && (score4 >= score5))
  234. highestScore = score4;
  235.  
  236. else if ((score5 >= score1) && (score5 >= score2) && (score5 >= score3) && (score5 >= score4))
  237. highestScore = score5;
  238.  
  239. return highestScore;
  240.  
  241. }
  242.  
  243. double calcScore(double &score1, double &score2, double &score3, double &score4, double &score5)
  244.  
  245. {
  246. double totalScore;
  247. double findLowest(double &);
  248. double findHighest(double &);
  249. findHighest(highestScore);
  250. findLowest(lowestScore);
  251. judgeTotal = (((score1 + score2 + score3 + score4 + score5) - (highestScore + lowestScore)) / 3);
  252.  
  253. return judgeTotal;
  254. }
Advertisement
Add Comment
Please, Sign In to add comment