Max & Min

I am having a problem finding the max and min in my program. The program ask the user to input grades and enter a negative number in order to stop inputting grades but when I tried to find the min it keeps giving me that negative number instead of the actual lowest grade how can I change that?

Thanks
add an if statement to the loop that's asking for input
For example you could use:

if (number < 0)
break;

or something along those lines.
This is what I have

1
2
3
4
5
6
7
8
9
10
11
12
13

int max = 0;
int min  = 100;

if (grad > max)
   {
       max = grad;
    }
else if (grad <min)
   {
	min = grad;
   }


This is only part of my program I entered grades like 40,60,90 and exit with a -4 and when I cout min it gives me the -4 instead of 40.
Well your problem is line 9.

else if (grad <min)

since the negative number is less than min it sets min = grad.

You could change the line to:
else if (grad <min && grad>0)

Please post the whole code so we can see what's going to be printed to the screen. Plus since you are defining the variables, not entirely sure where the -4 even comes from...this is why we need to see the rest of the code to see what exactly you're doing.
Thanks Fovv I had used else if (grad < min && grad > 0) earlier and it didn't work but I realize now that I had to flip max and min I was finding the max first so it was messing it up Thanks so much =)
No problem man. Happy to help because it helps me learn c++ as well :D
Yeah, this forum is really helpful especially if you are like me and make very obvious mistakes hahah.
Topic archived. No new replies allowed.