I'm having a problem with a program for my C++ class (which is going way too slowly for my liking). The program gets 5 test scores, finds the lowest one and "drops" it. Then averages the remaining 4 and outputs the average to the screen. I got it working except for one case, when the lowest score is equal to another score (e.g. 93 91 89 85 85).
First, what would be a better way to go about this? And second, what can do to fix the same score problem? Code for the problem function is below.
Any help would be greately appreciated. Thanks.
-Forbin
First, what would be a better way to go about this? And second, what can do to fix the same score problem? Code for the problem function is below.
code:<HR>Code:int findLowest(int score1, int score2, int score3, int score4, int score5) { int sum; if (score1 < score2) { if (score1 < score3) { if (score1 < score4) { if (score1 < score5) sum = score2 + score3 + score4 + score5; } } } else if (score2 < score1) { if (score2 < score3) { if (score2 < score4) { if (score2 < score5) sum = score1 + score3 + score4 + score5; } } } else if (score3 < score1) { if (score3 < score2) { if (score3 < score4) { if (score3 < score5) sum = score1 + score2 + score4 + score5; } } } else if (score4 < score1) { if (score4 < score2) { if (score4 < score3) { if (score4 < score5) sum = score1 + score2 + score3 + score5; } } } else if (score5 < score1) { if (score5 < score2) { if (score5 < score3) { if (score5 < score4) sum = score1 + score2 + score3 + score4; } } } return sum; }
Any help would be greately appreciated. Thanks.
-Forbin