C++/Still a problem.
Expert: vijayan - 12/7/2008
QuestionHey.
I've attempted your code. But there's still an error.
I want to try all the possibilites like MALE, maLE, feMAle. Yours only works for f, female, m and male. But if I type MALE and FEMALE it won't work. It will also not loop and ask me to enter the gender again.
Instead it shows the ""gender is incorrect\nplease renter the gender: " and executes. What I want it to do is loop and ask again for the gender if the gender entered is wrong.
Thanks.
Answerok. since you want to accept complete strings (and not just a single character), modify your loop to do something like:
std::string gender ;
std::cout << "please enter the gender: " ;
std::cin >> gender ;
// convert the string to all lower case
std::transform( gender.begin(), gender.end(), gender.begin(), ::tolower ) ;
if( ( gender != "male" ) && ( gender != "female" ) )
{
std::cout << "gender is incorrect\n" ;
// and repeat the loop
}