You are here:

C++/Still a problem.

Advertisement


Question
Hey.

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.

Answer
ok. 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
}  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.