Judges scores


This is a homework problem, but the only problem I am having trouble with is taking 5 scores, getting rid of the highest and lowest, then averaging out the rest. In the snippet below, it is only taking the last number entered, but not the rest. I have figured this out by reversing the numbers in different orders.
Not asking this to be solved, but where do I need to look. The score range is 0-10, largest is set at 0 and smallest is set at 11 (to allow everything else to be smaller initially.)

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
  sum = 0;
		for (int z = 1; z <= 5; z++) {

				cout << "Enter score #" << z << "." << endl;
				cout << fixed << setprecision(2);
				cin >> a;
				
				if (a <= 10 && a >= 0) {
					if (a > largest) {
						largest = a;
					}
					if (a < largest) {
						smallest = a;
					}
					if (a < smallest) {
						smallest = a;

					}

				}
				else {
					cout << "Please try again. " << endl;
				}
sum += a;
			}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int largest = 1 , smallest = 0 ;

if( a > largest )
{
       largest = a ;
}
else if( a < smallest )
{
       smallest = a ;
}
else if( smallest < a && a < largest )
{
       sum += a ;
       average = sum / z ;
}
 


tycose2014 excuse, if I translated correctly, you mean the average of the numbers between the smallest and largest, excluding the extremes themselves. then you should enter another variable, int average ..
Last edited on
Topic archived. No new replies allowed.