Untitled
unknown
plain_text
4 years ago
991 B
12
Indexable
#include <iostream>
using namespace std;
int main ()
{
const int SENTINEL = -99;
int num,
low,
high,
run = 0;
do
{
cout << "Please enter a number: ";
cin >> num;
while (!cin) {
cin.clear(); //Reset the flags, so you can use cin again
cin.ignore(100, '\n'); //Empty the buffer
cout << "Make sure you input a number. Try Again: ";
cin >> num;
}
if (run == 0)
{
high = num;
low = num;
}
else if(num < low && num != -99)
{
low = num;
}
else if (num > high && num != -99)
{
high = num;
}
run++;
} while(num !=-99);
cout << "Smallest Number is: " << low << endl;
cout << "Largest Number is: " << high << endl;
return 0;
}
Editor is loading...