So I have been stuck on this part for a while...
I have been trying to make gender for my character so i could use he or she depending on gender, but cant seem to find the right way to do it.
The way I have it right now is sufficient but it is certainly not the best, if someone could explain or change my code so that when a user entered their gender it would associate that with "he" (for male) or "she" (for female) I would be very thankful... please respond.
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Welcome, please enter your player's name here." << endl;
string playerName;
cin >> playerName;
cout << "Oh, so you are " << playerName << ".\nIf so click 'y' if not click 'n'" <<endl;
char choice;
cin >> choice;
if (choice=='y')
{
cout << "Well then we are ready to begin our journey." << endl;
}
if (choice=='n')
{
cout << "Then what is your name?" << endl;
cin >> playerName;
}
cout << "Is your player male (enter 'he') or female (enter 'she')?" << endl;
string gender;
cin >> gender;
cout << playerName << " is walking through the woods when " << gender << " stumbles across a fork in the trail." << endl;
well u can accept the choice into an integer variable g: 0 for male and 1 for female, and then assign the value "He" or "she" accordingly into string.............Hope this helps.......... :)
From what ResidentBiscuit has said. Maybe you should use a do-while loop for input.
Also, what mj1709 said, maybe consider taking away the ability of the user changing the string: