Display the largest and smallest integers

I have this programming question that asks a user to enter a series of integers, to end input of the integers the user needs to input -99. Once all the integers are inputted I need to display the largest and smallest integer. As a hint the professor asked us to get the first input by the user and initialize the two vairbales (highest, lowest) with it.

So far I have created the following program code which asks the user to enter an integer which I named (number1) and then uses a while loop to determine if the user entered -99, if -99 is not entered it asks the user to enter another integer.

#include <iostream>
using namespace std;
int main ()
{

int number1,number2,lowest,highest;

cout << " Enter as many integers as you like\n";
cout << " then enter -99 when finished\n\n";
cout << " Please enter an integer " << " : ";
cin >> number1;

highest = number1;
lowest = number1;

while(number1 != -99)
{
cout << " enter another integer ";
cin >> number1;
}



return 0;
}


My question is: What type of expression is needed to compare the numbers entered to determine which integer is the largest and smallest? I dont quite understand how to display the largest and the smallest number. I have searched the FAQ's and other posts and am unable to find an answer tot his question. Any help or suggestions would be appreciated.


Every time through the loop check to see if the number entered is larger than the largest and if it is, set largest to that number. Then check to see if it is the smallest and if it is, set smallest to that number.

You need if-else-statements. Read here for more information
http://www.cplusplus.com/doc/tutorial/control.html
Thanks for the helpful tips, I got the code to work...much appreciated.
Topic archived. No new replies allowed.