The code below gives me the maximum odd number and the minimum even number of a list of numbers that the user type. However, for the loop to stop the user needs to type 1000. Is there a better way (without having to have a "stopping" number, just in case I need this number to be somewhere on the list) to get the same results?
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int x, maxi, mini;
cout<<"Enter a list of numbers and 1000 as the last number: ";
maxi=0;
mini=1000;
for(;;)
{
cin>>x;
if(x==1000){break;}
if((x > maxi) && (x%2==1)){ maxi=x;}
else if((x<mini)&& (x%2==0)){mini=x;}
}
cout<<"maximum odd number is: "<<maxi<<endl<<endl;
cout<<"minimum even number is: "<<mini<<endl<<endl;
system("pause");
return 0;
}