lowest and highest number

I'm having trouble coding the highest and lowest mark.
The rest of code can run except these two.
I would really appreciate your help.

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
 #include <iostream>
using namespace std;
int main ()
{
	float mark,i, highest,lowest,average;
	float total=0;
	while (i<=3)
	
	{
	cout <<"Enter mark:"<<endl;
	cin>>mark;
	if (mark>=80)
	cout <<"A"<<endl;
		else if (mark>=60)
			cout<<"B"<<endl;
				else if (mark>=40)
					cout <<"C"<<endl;
					else
						cout <<"D"<<endl;
	

		total = total + mark;

		i=i+1;
	}

	if (mark>highest)
 {
 	highest=mark;
 	cout<<"highest mark is: "<<highest << endl;
 }
		if (mark<lowest)
 {
 	lowest=mark;
 	cout<<"lowest mark is: "<<lowest << endl;
 }
	
	cout<<"Total mark: "<<total<<endl;
	average = total/3;
	cout<<"Average mark:"<<average<<endl;

	system("PAUSE");
	return 0;	
in line 5, make i=0.Also for highest and lowest.

And the while loop enters the marks three times,but the if(marks>highest) statement gets the value of the last marks.
Enter the both if statements inside the while loop.
Highest should be set to 0, but lowest should be set to a great value. Otherwise if (mark < lowest) will always evaluate as false. (Supposed that a mark cannot be negative).

If a mark can be at most e.g. 100 initialise lowest with that value.
If a mark can be any value (>0) float lowest = std::numeric_limits<float>::infinity(); seems to be a good initial lowest mark.

Regards,
mathes
There are two viewpoints and approaches. A fundamental question is:
What is the maximum value if there are no values at all?
Do we give a bogus value or do we treat the situation/error in some different way?

In this program there must always be values. We use extreme bogus value to ensure
that the real values will replace it.

Whether or not there are always values, one can initialize the tracker (min / max)
with the first real value. That ensures that there is no poorly chosen bogus value.
The bad part is that then the first input has to be handled differently from all the rest.
Topic archived. No new replies allowed.