removal of highest and lowest number

Okay, I have a problem that requires the user to input scores for contestants for five judges (working), maintain an input validation (working), and make usage of removing the highest and lowest number through the usage of "findHighest" and "findLowest" functions. It's very frustrating because the program itself compiles and runs but doesn't properly do the math if I input two of the same value for the highest or the lowest value.

So if I do two ratings of ten and any other three values it simply doesn't average the three remaining scores properly.

I honestly have no idea where to progress, add, edit, or what to do from here. Just some direction would be greatly appreciated as my professor has offered me nothing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include <cmath>


using namespace std;


// Prototype

void get_data(float &score);
void calcScore (float &averageScore, float judge1, float judge2, float judge3, float judge4, float judge5);
int findHighest (float judge1, float judge2, float judge3, float judge4, float judge5);
int findLowest (float judge1, float judge2, float judge3, float judge4, float judge5);

// Calculate The Final Average

void calcScore (float&averageScore, float judge1, float judge2, float judge3, float judge4, float judge5)
{
    float lowest;
    float highest;
    float removedHighLow;
    float totalScore;
    
    totalScore = judge1 + judge2 + judge3 + judge4 + judge5;
    
    // Get the lowest score plugged into a variable
    lowest = findLowest (judge1, judge2, judge3, judge4, judge5);
    
    // Get the highest score plugged into a variable
    highest = findHighest (judge1, judge2, judge3, judge4, judge5);
    
    // Drop the highest and lowest scores
    
    removedHighLow = totalScore - (lowest + highest);
    
    // Obtain the average of the three scores
    
    averageScore = removedHighLow / 3;
    
    
    
}


// Find the highest value.

int findHighest (float judge1, float judge2, float judge3, float judge4, float judge5)
{
    if (judge1 > judge2 && judge1 > judge3 && judge1 > judge4 && judge1 > judge5)
        
        return judge1;
    
    
    else if (judge2 > judge1 && judge2 > judge3 && judge2 > judge4 && judge2 > judge5)
        
        return judge2;
    
    
    else if (judge3 > judge1 && judge3 > judge2 && judge3 > judge4 && judge3 > judge5)
        
        return judge3;
    
    
    else if (judge4 > judge1 && judge4 > judge2 && judge4 > judge3 && judge4 > judge5)
        
        return judge4;
    
    else
        
        return judge5;
}

// Find the lowest value.

int findLowest (float judge1, float judge2, float judge3, float judge4, float judge5)
{
    if (judge1 < judge2 && judge1 < judge3 && judge1 < judge4 && judge1 < judge5)
        
        return judge1;
    
    
    else if (judge2 < judge1 && judge2 < judge3 && judge2 < judge4 && judge2 < judge5)
        
        return judge2;
    
    
    else if (judge3 < judge1 && judge3 < judge2 && judge3 < judge4 && judge3 < judge5)
        
        return judge3;
    
    
    else if (judge4 < judge1 && judge4 < judge2 && judge4 < judge3 && judge4 < judge5)
        
        return judge4;
    
    else
        
        return judge5;
    
    
}


int main()
{
    
    
    float averageScore;
    
    
    float judge1;
    // Actual call
    get_data(judge1);
    
    float judge2;
    // Actual call
    get_data(judge2);
    
    float judge3;
    // Actual call
    get_data(judge3);
    
    float judge4;
    // Actual call
    get_data(judge4);
    
    float judge5;
    // Actual call
    get_data(judge5);

  
    
    
    calcScore (averageScore, judge1, judge2, judge3, judge4, judge5);
    
    cout << "The average score for this performer is " << averageScore << " points!" << endl;


}



// Formal Function Heading & Details
void get_data (float &score)
{
    cout << "Please enter a score: ";
    cin >> score;

while (score > 10.0 || score < 0.0)
    {
    cout << "ERROR: Please enter a judge's score between '0' and '10': ";
    cin >> score;
    
    }

}
First of all; never blame your professor because you can't do the problem: think about it: why should anyone want to help you if you criticise them?

Some points about your program:
- You make it too long, complex and difficult to use by having five variables judge1, judge2, judge3, judge4, judge5. I suggest that you use an array judge[] (which should be declared to have five elements. You can then use simple loops to carry out your calculations and it will be a much shorter program and more easy to debug.

- Your findHighest and findLowest routines are declared to return integers, yet you are trying to return floats (the values of the judges). Many compilers will complain; all will round one way or another. Make up your mind whether you want an int or a float returned (you could do it either way, but make it consistent; probably given what you do later you would be better to return a float).

- If you look at the findHighest and findLowest routines they are very much premised on having five judges; change this and these functions become pointless. This is another reason for using arrays.

- To find the maximum of elements in an array it is roughly 2 lines of code (plus some type declarations at the start and a return):
* initialise maximum as the first element of the array;
* loop through the remaining elements and replace maximum with an element value if it is bigger.
- Similarly for the minimum.
if I input two of the same value for the highest or the lowest value.
This is not possible: Either you input all the same value or you have either min or max or both.

I don't see what your problem is?
"First of all; never blame your professor because you can't do the problem: think about it: why should anyone want to help you if you criticise them?"

I didn't mean it that way. That's the way that you took it. Regardless, I was a little harsh in my statement. He's been great so far in the 8 weeks of class I have had him. Then again, I haven't really needed any help until now and he hasn't been direct or clear in his "help."

Moving on, sadly we haven't hit arrays so I am unable to use that type of code.

coder777, If I enter 10, 10, 5, 9, 8 for example the average is returned as 9.66667 points. So the findHighest and findLowest functions are breaking if I enter two of the same highest values or same lowest values because it's not properly removing one of the higher or lower numbers.

With that being said, I cannot use array functions or

1
2
3
4
5
6
7
8
9
"int findHighest (float judge1, float judge2, float judge3, float judge4, float judge5)
{
return std::max ({judge1, judge2, judge3, judge4, judge5})
}"

"int findLowest (float judge1, float judge2, float judge3, float judge4, float judge5)
{
return std::min ({judge1, judge2, judge3, judge4, judge5})
}"


Which both make the program work perfectly. Apparently it won't compile on certain compilers for whatever reason. Works on Xcode however.

But he still wants the "logic" for selecting the higher and lower number.

Again, any help is greatly appreciated. Thank you for the suggestions.
don't know if this what you asking.
But i would find the lowest like this.



int findLowest(int scoreOne, int scoreTwo, int scoreThree, int scoreFour, int scoreFive)
{
int lowest = scoreOne;

if (lowest > scoreTwo) lowest = scoreTwo;

if (lowest > scoreThree) lowest = scoreThree;

if (lowest > scoreFour) lowest = scoreFour;

if (lowest > scoreFive) lowest = scoreFive;

return lowest;
}
Topic archived. No new replies allowed.