vendredi 31 juillet 2020

Trying to define strings in an if statment in C++

I want to have a gender system in what I'm coding, so in dialogue there are pronouns, but since the strings are defined in an if statement they come up blank. Is there a better way to do this?

int gender;
string pronoun;
string pronoun1;
string pronoun2;
string pronouns3;
string namingGender;

cout << "Please enter your gender \n1. Male \n2. Female \n3. Other" << endl;
cin >> gender;
if (gender == 1) {
    string namingGender = " saucy sir";
    string pronoun = " he ";
    string pronoun1 = " him ";
    string pronoun2 = " his ";
    string pronoun3 = " he's ";
    cout << "Have fun playing Insert-Name-Here!" << endl;
}
else if (gender == 2) {
    string namingGender = " manseva madam";
    string pronous = " she ";
    string pronou1 = " her ";
    string pronoun2 = " her ";
    string pronoun3 = " she's ";
    cout << "Have fun playing Insert-Name-Here!" << endl;
}
else if (gender == 3) {
    string nammingGender = " majestic mate";
    string pronoun = " they ";
    string pronoun1 = " them ";
    string pronoun2 = " their ";
    string pronoun3 = " they're ";
    cout << "Have fun playing Insert-Name-Here!" << endl;
}
else {
    cout << "You  did not enter 1 2 or 3...guess your other than" << endl;
    string nammingGender = " majestic mate";
    string pronoun = " they ";
    string pronoun1 = " them ";
    string pronoun2 = " their ";
    string pronoun3 = " they're ";
    cout << "Have fun playing Insert-Name-Here!" << endl;
}
    
cout << "By the way, what is your name... " << namingGender << "?" << endl;
cin >> playerName;

Aucun commentaire:

Enregistrer un commentaire