fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. void getJudgeData(int &x);
  7. double findLowest(int a, int b, int c, int d);
  8. double findHighest(int a, int b, int c, int d);
  9. void calcScore (int a, int b, int c, int d);
  10.  
  11.  
  12.  
  13. int main() {
  14. int s1,s2,s3,s4;
  15. getJudgeData(s1);
  16. getJudgeData(s2);
  17. getJudgeData(s3);
  18. getJudgeData(s4);
  19.  
  20. calcScore (s1,s2,s3,s4);
  21.  
  22.  
  23.  
  24.  
  25. return 0;
  26. }
  27.  
  28.  
  29. void getJudgeData(int &x) {
  30. cout << " Enter the judge's score: \n";
  31. cin >> x;
  32.  
  33. while (x < 0 || x > 20) {
  34. cout << "That is an invalid score. Please try again.\n"
  35. << "The score must be from 0 to 20.\n";
  36. cin >> x;
  37. }
  38. }
  39.  
  40. double findLowest(int a, int b , int c , int d) {
  41. int lowest = a;
  42.  
  43. if (b < lowest) {
  44. lowest = b;
  45. }
  46. if (c < lowest) {
  47. lowest = c;
  48. }
  49. if (d < lowest) {
  50. lowest = d;
  51. }
  52.  
  53. return lowest;
  54. }
  55.  
  56. double findHighest(int a, int b, int c, int d){
  57. int highest = a;
  58.  
  59. if (b > highest) {
  60. highest = b;
  61. }
  62. if (c > highest) {
  63. highest = c;
  64. }
  65. if (d > highest){
  66. highest = d;
  67. }
  68. return highest;
  69. }
  70.  
  71. void calcScore(int a, int b, int c, int d) {
  72.  
  73. double low = findLowest (a,b,c,d);
  74. double high = findHighest( a,b,c,d);
  75. cout << "The performers final score is: "
  76. << ((a + b + c + d - low - high) / 2.0) << endl;
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
Success #stdin #stdout 0.01s 5316KB
stdin
10 11 15 16
stdout
 Enter the judge's score: 
 Enter the judge's score: 
 Enter the judge's score: 
 Enter the judge's score: 
The performers final score is: 13