Luxana
asked on
easy quick question - validation
Hello Experts,
Can somebody explain me on beginner level how should I rewrite this code? I'm trying to do validation for char variable with while loop.
do {
cout << "Please enter your sex\n";
cout << "\t M - Male\n";
cout << "\t F - Female\n";
cout << " ==> ";
cin >> s;
} while ( s != 'f' );
this works but just for 'f' but when I add "or"
do {
cout << "Please enter your sex\n";
cout << "\t M - Male\n";
cout << "\t F - Female\n";
cout << " ==> ";
cin >> s;
} while ( s != 'f' || s != 'F' || s != 'm' || s != 'M');
thanks
Can somebody explain me on beginner level how should I rewrite this code? I'm trying to do validation for char variable with while loop.
do {
cout << "Please enter your sex\n";
cout << "\t M - Male\n";
cout << "\t F - Female\n";
cout << " ==> ";
cin >> s;
} while ( s != 'f' );
this works but just for 'f' but when I add "or"
do {
cout << "Please enter your sex\n";
cout << "\t M - Male\n";
cout << "\t F - Female\n";
cout << " ==> ";
cin >> s;
} while ( s != 'f' || s != 'F' || s != 'm' || s != 'M');
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks you all
I'll accept zzray answer because of his explanation and rest of answers assist.
I'll accept zzray answer because of his explanation and rest of answers assist.
while ( s!='f' && s!='F' && s!='m' && s!='M')