Calculation Error in findLowest() and findHighest()

For this program I was looking to input five scores - take the lowest and highest scores and drop them
Take the remaining scores and avg them
I have written the program but I am having some issues when calculating the avg
When testing my program it works properly if the score from judge one is the lowest but it will now work properly for any other judges being the lowest.

Ex: I will enter 2,1,5,4,3 so it should drop the 1 & 5 and come out with the avg of 3 but the result is 2.6667

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  int findLowest(double scoreOne,double scoreTwo,double scoreThree, double scoreFour,double scoreFive)
{
    double lowest;

if ((scoreOne < scoreTwo) && (scoreOne < scoreThree) &&
    (scoreOne < scoreFour) && (scoreOne < scoreFive)) 
{
    lowest = scoreOne;
}
else if ((scoreTwo < scoreOne) && (scoreTwo < scoreThree) &&
         (scoreTwo < scoreFour) && (scoreTwo < scoreFive))
{
    lowest = scoreTwo;
}

//and so on... (if you would like to see the rest let me know)

return lowest;
}


The int findHighest is similar but the less than symbols are switched obviously.

for the calcAverage() function I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
double calcAverage(double OneScore,double twoScore,double threeScore, double fourScore,double fiveScore)
{
    double lowest, highest, sum;

    lowest=findLowest(OneScore,twoScore,threeScore,fourScore,fiveScore);
    highest=findHighest(OneScore,twoScore,threeScore,fourScore,fiveScore);

    sum = (OneScore + twoScore + threeScore + fourScore + fiveScore);
    sum = sum - lowest;
    sum = sum - highest;
    sum = sum / 3;

    cout<<"\nAfter droping highest and lowest scores\n";
    cout<<"Your average score is "<<sum << endl;

return 0;
}
Hmm. What if there were 9 judges instead of 5? The code would start to get pretty crazy. You're much better off storing the scores in a vector. Once you do that, you can use a loop to find the highest, lowest and sum.
Topic archived. No new replies allowed.