need help with C++

need coding for a program that allows user to enter numbers and then display greatest and lowest value (c++)
google it
Google results only show how to display highest and lowest of numbers already assigned inside an array which i already know and not how to display highest and lowest of numbers i entered through the keyboard.
Instead of initializing your array. Enter whats inside the array.

1
2
3
4
5
6
int hey[5];

for(int i = 0; i < 5; i++)
{
    cin >> hey[i];
}
do something like this:
1
2
3
4
5
6
7
8
9
10
int largest = INT_MIN, lowest = INT_MAX, num;
/*INT_MAX and INT_MIN represent the largest and lowest possible integers(int)*/
while(cin >> num)//use CTRL + D (end-of-file) to exit loop
{
     lowest = min(lowest, num);//returns the lesser value of the two
     largest = max(largest, num);//returns the higher value
}

cout << "The largest is: " << largest
        << " and the lowest is: " << lowest << endl;
Last edited on
@Faison. That is a infinite loop.
No, it's not. The >> function reads ints from the stream cin until the End-of-File character is read. That can be done by entering CTRL+Z or CTRL+D. Sorry I forgot to mention that. So after antering all numbers, enter the End-of-File to exit the loop.
Topic archived. No new replies allowed.