cout<<"\nPlease Enter an Operator (1 for + , 2 for - , 3 for * or 4 for /): ";
cin>> operator_number_value;
while ( !( cin>> operator_number_value ) ) {
cerr<<"Invalid Input, Try Again: ";
cin.clear();
cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
}
while ( operator_number_value != 1 || 2 || 3 || 4 ) {
cout<<"Invalid Input, Try Again: ";
cin>> operator_number_value;
}
the problem is the 2 while loops are to prevent 2 different types of input error. the first loop for stopping letter input from crashing the program as it is a int variable. the second loop is for only allowing 1,2,3 or 4 as valid input values, but if i test the second while loop then test the first the program drops to an infinite loop.
any help appreciated thanks in advance.

New Topic/Question
Reply




MultiQuote




|