Link to home
Start Free TrialLog in
Avatar of Luxana
LuxanaFlag for Australia

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

SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r_a_j_e_s_h
r_a_j_e_s_h

simply change the || to && .....

while ( s!='f' && s!='F' && s!='m' && s!='M')
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luxana

ASKER

thanks you all

I'll accept zzray answer because of his explanation and rest of answers assist.