Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4.  
  5. void getJudgeData(int);
  6. void calcScore(double [], double&);
  7. int findLowest(double []);
  8. int findHighest(double []);
  9.  
  10. double score[4];
  11.  
  12. int main(void) {
  13.     double  final_score;  // Final result after calculations.
  14.  
  15.     for (int i = 1; i <= 5; ++i) {
  16.         getJudgeData(i);
  17.  
  18.     }
  19.  
  20.     calcScore(score, final_score);
  21.  
  22.     cout << "Final score: " << final_score;
  23.  
  24.     cin.get();
  25.     return 0;
  26. }
  27.  
  28.  
  29. /*  Promps for a score to be entered.  */
  30. void getJudgeData(int judge) {
  31.     double input;
  32.     bool loop = false;
  33.  
  34.     while (loop == false) {
  35.         cout << "Judge " << judge << ", enter your score: ";
  36.         cin >> score[--judge];
  37.  
  38.         input = score[--judge];
  39.         if (input < 0 || input > 10) {
  40.             cout << score << " is an invalid entry." << endl;
  41.             cin.ignore();
  42.             cin.get();
  43.             system("CLS");
  44.         }
  45.         else {
  46.             cout << "Thank you." << endl;
  47.             loop = true;
  48.         }
  49.  
  50.         cin.ignore();
  51.         cin.get();
  52.         system("CLS");
  53.     }
  54. }
  55.  
  56. /*  Calculates the average of the score minus the highest and lowest numbers.  */
  57. void calcScore(double score[], double &final_score) {
  58.     final_score = ((score[0] + score[1] + score[2] + score[3] + score[4]) -
  59.         (findLowest(score) +
  60.         findHighest(score))) / 3;
  61. }
  62.  
  63. /*  Finds the lowest of 5 numbers.  */
  64. int findLowest(double score[]) {
  65.     int lowest;
  66.  
  67.     if (score[0] < lowest)
  68.         lowest = score[0];
  69.     if (score[1] < lowest)
  70.         lowest = score[1];
  71.     if (score[2] < lowest)
  72.         lowest = score[2];
  73.     if (score[3] < lowest)
  74.         lowest = score[3];
  75.     if (score[4] < lowest)
  76.         lowest = score[4];
  77.  
  78.     return lowest;
  79. }
  80.  
  81. /*  Finds the highest of 5 numbers.  */
  82. int findHighest(double score[]) {
  83.     int highest = 0;
  84.  
  85.     if (score[0] > highest)
  86.         highest = score[0];
  87.     if (score[1] > highest)
  88.         highest = score[1];
  89.     if (score[2] > highest)
  90.         highest = score[2];
  91.     if (score[3] > highest)
  92.         highest = score[3];
  93.     if (score[4] > highest)
  94.         highest = score[4];
  95.  
  96.     return highest;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement