Please help me with this

I am trying to make a simple game. The part I'm struggling with is giving the player the option of choosing to go a certain direction.

In my case it's something like this:

cout >> "Would you like to come with me to my house, stay here by your self, or go home with your friends?;

How do I make is so people can choose one of the paths by typing like "go with you" or "stay here" or "go with friends"

Please explain this as basic as you can.

Here's a piece of the game:

1
2
3
4
cout << name << " Would you like to come with me, go home with your friends, or stay here by yourself?";
if (stay here);
cin >> "stay here";
cout << "You stay where you're at.; 


I'm struggling here guys. Please help.
declare strings called stay and go with their corresponding responses in the game. then if the string inputted to cin is "stay here" the character will cout the appropriate response and vice versa
Last edited on
Gawaine I appreciate your reply but I have no clue what you just said. Can you give me an example code or something please?
Here's what we have for the part: It's running fine but when I type "go with" in game it simply ignores everything and goes into the final 10000s sleep...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	cout << "((Type 'go with' to go with the old man or type 'stay' to stay where you are.))";


	string choose;

	cin >> choose;

	if (choose == "go with")
	{
		cout << "You muster up your last bit of strength and begin following the Hecktor.";
	}
	else if (choose == "stay")
	{
		cout << "You decide to stay where you are and continue resting.";
	}
	Sleep(100000);
}
1
2
string stay = "stay here";
string go = "go home";


Then depending on what you input you determine what is printed out.

1
2
3
4
5
6
string str;
cin >> str;
if (str == go)
    put necessary code;
else if (str == stay) 
    put necessary code;
you just have to compare the answer that is input through cin with what is programmed as a valid answer.
Thanks for helping Gawaine but I have another question,

Could the problem be that I'm using "go with"? I got it to work using the word "go"

And the word "stay" always worked.

But when I used 2 words for one string it didn't work.
It shouldn't be like that. I mean a string is an array of characters and a space is a character so it shouldn't throw it off. Try what I showed you and declare the answers as strings in their own right and the compare the string choose with go or stay. If that doesn't solve it then I guess just use simpler answers like "stay" or "go".
1
2
string str;
cin >> str;


The problem is on line 2. Using cin with a string that way only gets the first word. You will need to use something like std::getline() to get an entire line.
Thank you to Gawaine and firedraco. This was my first time posting for help on this forum and both of you have been extremely helpful.
Topic archived. No new replies allowed.