Testing a string!?

cout << "Is your player male (enter 'he') or female (enter 'she')?" << endl;

string gender;
cin >> gender;

// I'm trying to test whether the user entered he or she.

while (gender==//WHAT SHOULD I PUT HERE?)

do {

}
while (gender=="he")

I note that you're using a while loop. Are you expecting the player to change gender mid-game?
you don't change gender mid game moschops ;)? i also note that you while do? where is the second while?
And if the user enters "he", the condition will evaluate to true. Which means that you'll be left with an infinite loop.
yeah for infinite loops which is actually not true because he could have an exit or abort or return or change his gender
I'm guess you're after something like this:
1
2
3
4
5
6
7
string gender;
do {
    cout << "Is your player male (enter 'he') or female (enter 'she')?" << endl;
    cin >> gender;
    
    // loop until gender is either "he" or "she"
} while( gender != "he" && gender != "she" );

cout << "Is your player male (enter 'he') or female (enter 'she')?" << endl;

string gender;
cin >> gender;

// I'm trying to test whether the user entered he or she.

while (gender==//WHAT SHOULD I PUT HERE?)

do {

}


isnt it as simple to find what the user entered as:
1
2
3
4
5
6
string gender;

cout << "Is your player male (enter 'he') or female (enter 'she')?" << endl;
getline (cin,gender);

cout << "The user entered " << gender << " for their selection." << endl;
Last edited on
hes not trying to find it hes trying to test it
Topic archived. No new replies allowed.