Finding Highest and lowest and average scores

Hey guys, I am taking a Logic and Programming course at my local community college and am studying C++. I am stuck on a lab assignment that asks you to enter five scores then find the lowest score and the highest score and then find the average of the excluded scores so it should end up looking like..

Please enter five scores.
First score: 15.7
Second score: 14.2
Third score: 14.8
Fourth score: 15.5
Fifth score: 15.0

Lowest score: 14.2
Highest score: 15.7
Average score with highest score and lowest score excluded: 15.1

Press any key to continue . . .

All I receive for right now is

Please enter five scores.
First score: 15.7
Second score: 14.2
Third score: 14.8
Fourth score: 15.5
Fifth score: 15.0
lowest score : 0
highest score: 15.7

Why isn't my lowest score found?? and is there any easier way to do what I am doing? Thanks!

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
 #include <cstdlib>
#include <iostream>
using namespace std;

int main()
{
    //Declare variables
	    double a = 0.0;
    	double b = 0.0;
    	double c = 0.0;
    	double d = 0.0;
    	double e = 0.0;
    	double lowest=0.0;
    	double highest=0.0;
    	
	//Request input
	cout << "Please enter five scores."<<endl;
    	cout << "First score: ";
    	cin >> a;
    	cout << "Second score: ";
    	cin >> b;
    	cout << "Third score: ";
    	cin >> c;
    	cout << "Fourth score: ";
    	cin >> d;
    	cout << "Fifth score: ";
    	cin >> e;
   	
	//Determine the lowest score
    	if (a < b && a < c && a<d && a<e)  
    	{
        	lowest=a;
    	}
    	
    	else if (a > b && a > c && a>d && a>e)  
    	{
        	highest=a;
    	}
    	
    	else if (b < a && b < c && b < d && b < e)   
    	{
        	lowest=b;
    	}
    	
    	    	else if (b > a && b > c && b > d && b > e)   
    	{
        	highest=b;
    	}
    	
    	else if (c < a && c < b && c < d && c < e)
    	{
        	lowest=c;
    	}
    	
    		else if (c > a && c > b && c > d && c > e)
    	{
        	highest=c;
    	}
      
    	else if (d < a && d < b && d < c && d < e)  
    	{
        	lowest=d;
    	}
    	
    	    	else if (d > a && d > b && d > c && d > e)  
    	{
        	highest=d;
    	}
    	
    	    	else if (e > a && e > b && e > c && e > d)  
    	{
        	highest=e;
    	}
    
    	
    	else
    	{ (e < a && e < b && e < c && e < d);
        	lowest=e;
    	}
    	
    	
    //Display the lowest and highest scores
    cout << "Lowest Score: "<<lowest<< endl;
    cout << "Highest Score: "<<highest<<endl;
      
    	system("pause");
    	return 0;
}
Last edited on
Are you allowed to use arrays?
The better question is "what is an array?" haha

We haven't really learned about them. I am sure it would be okay to use them though he hasn't said otherwise.
Last edited on
What is an arrays:
http://www.cplusplus.com/doc/tutorial/arrays/

basically list of boxes with each hold a value. So no more a b c d, but just grades.

it would look something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int grades[5];

for(int index = 0; index < 5; index++){
    cin >> grades[index]
}

int maxGrade= 0; // smallest number
int minGrade = 9999; //large number
int maxGradeIndex;
int minGradeIndex;

for(int index = 0; index < 5; index++){
    if( grade[index] > maxGrade){
         maxGrade = grade[index];
         maxGradeIndex = index;
    } else  if( grade[index] < minGrade){
         minGrade = grade[index];
         minGradeIndex = index;
    }
}

and then output it:

I will leave it to you.

You might be villing to use double instead of int.
Yeah, we have never been exposed to that in class. As of right now that is going over my head but I could learn and attempt to use that for this assignment.
Topic archived. No new replies allowed.