I am having problems getting correct output for my code that is supposed to read an unspecified number of integers until EOF and then output the maximum and minimum values entered. I must be overlooking something simple as I have been working on this for longer than I care to disclose. Any help would be greatly appreciated.
usingnamespace std;
int main()
{
int number,maximum,minimum;
int count = 0;
cout << "Enter a number, EOF to quit: " << endl;
cin >> number;
number=maximum=minimum;
while( cin >> number )
{
if ( number > maximum )
maximum=number;
elseif(number < minimum)
minimum=number;
count++;
}
if ( count == 0 )
{
cout << "No data was entered, there are no minimum or maximum values." << endl; // If no data is entered (only the EOF) then this message is displayed
return 1;
}
elseif ( count != 0 )
cout << "The maximum number is: " << maximum << endl
<< "The minimum number is: " << minimum;
return 0;
}