fork download
  1. //Vanessa Ramirez CSC5 Chapter 6, P. 371, #10
  2. //
  3. /******************************************************************************
  4. // LOWEST SCORE DROP
  5. ________________________________________________________________________________
  6. This program calculates the average of five test scores after dropping the
  7. lowest score.
  8. ________________________________________________________________________________
  9. INPUT
  10. score1 - First test score
  11. score2 - Second test score
  12. score3 - Third test score
  13. score4 - Fourth test score
  14. score5 - Fifth test score
  15.  
  16. OUTPUT
  17. average - Average of the four highest scores
  18. *******************************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. // Function protoype
  23. void getScore(int &score);
  24. void calcAverage (int score1, int score2, int score3,
  25. int score4, int score5);
  26. int findLowest(int score1, int score2, int score3,
  27. int score4, int score5);
  28.  
  29.  
  30. int main()
  31. {
  32. // Declare variables
  33. int score1;
  34. int score2;
  35. int score3;
  36. int score4;
  37. int score5;
  38.  
  39. //Get the five test scores
  40. cout << "Enter test score 1: " << endl;
  41. getScore(score1);
  42.  
  43. cout << "Enter test score 2: " << endl;
  44. getScore(score2);
  45.  
  46. cout << "Enter test score 3: " << endl;
  47. getScore(score3);
  48.  
  49. cout << "Enter test score 4: " << endl;
  50. getScore(score4);
  51.  
  52. cout << "Enter test score 5: " << endl;
  53. getScore(score5);
  54.  
  55. // Calculate and dispay the average
  56. calcAverage(score1, score2, score3, score4, score5);
  57.  
  58. return 0;
  59. }
  60. //getScore
  61. // Drops the lowest score and displays the average of the four highest test
  62. //scores.
  63. void getScore(int &score)
  64. {
  65. cin >> score;
  66.  
  67. while (score < 0 || score > 100)
  68. {
  69. cout << "Invalid score. Enter a scope from 0 to 100: ";
  70. cin >> score;
  71. }
  72. }
  73.  
  74. void calcAverage(int score1, int score2, int score3, int score4, int score5)
  75. {
  76. int lowest;
  77. int total;
  78. double average;
  79.  
  80. //Find the lowest score
  81. lowest = findLowest(score1, score2, score3, score4, score5);
  82.  
  83. // Add the five scores
  84. total = score1 + score2 + score3 + score4 + score5;
  85.  
  86. //Drop the lowest score and calculate the average
  87. average = (total - lowest) / 4.0;
  88.  
  89. // Display the average
  90. cout << endl << "Average of the four highest scores: " << average << endl;
  91. }
  92.  
  93. int findLowest(int score1, int score2, int score3, int score4, int score5)
  94. {
  95. int lowest;
  96.  
  97. lowest = score1;
  98.  
  99. if (score2 < lowest)
  100. {
  101. lowest = score2;
  102. }
  103. if (score3 < lowest)
  104. {
  105. lowest = score3;
  106. }
  107. if (score4 < lowest)
  108. {
  109. score4 = lowest;
  110. }
  111. if (score5 < lowest)
  112. {
  113. score5 = lowest;
  114. }
  115. return lowest;
  116. }
Success #stdin #stdout 0s 5312KB
stdin
90 
75
88
60
95
stdout
Enter test score 1: 
Enter test score 2: 
Enter test score 3: 
Enter test score 4: 
Enter test score 5: 

Average of the four highest scores: 83.25