Im trying to get the smallest number out of a series of user generated numbers.
i can correctly get the largest number but i always get the negative 99 for the smallest.
im working out of a c++ book that does not provide solutions, i tried to catch the -99 but it didn't work
as you can see i commented it out.
i know someone is going to suggest it (dont use a neg number or try an array)
but the challenge says to do it WITHOUT using arrays and i HAVE to use -99 to quit.
any suggestions
int main()
{
int counter, input, largest = 0, smallest = 0;
cout << "Please enter a series of numbers so i can find the largest and smallest." << endl;
cout << "Enter -99 to indicate you are done entering numbers." << endl;
do
{
cout << "number: ";
cin >> input;
// if (input == -99)
// {
// input = 0;
// }
if (input < smallest)
{
smallest = input;
}
if (input > largest )
{
largest = input;
}
} while (input != -99);
//always gives -99
cout << "After searching the smallest is: " << smallest << endl;
// correct largest
cout << "After searching largest is: " << largest << endl;
return 0;
}