C++ Strings

I have four choices i want the choices to be north south east and west I'm putting in string north; string south; string east; string west; when i put in cin >> north; cin >> south; cin >> east; cin >> west; no matter which i type in it shows four blanks and then all four options. Can someone show me an example of how to do it to make it work the way I wanted.
Last edited on
Post your code and we can help you to correct it.
I think you should get one string and then check for conditions
eg:
1
2
3
4
5
6
7
8
9
string input;
cin >> input;
if (input=="north")
{
    //do something
}else if (input=="east")
{
   //do something else
}//... 
that worked thanks
next problem I got is i need to be able to have an option for north, like...

if chose north option a-b
if chose south option a-b

sorry this is my first day with code I'm doing my best this is my code though

#include <iostream>
#include <string>

using namespace std;

// This is the game named, Awaken
int main()
{
string firstName;
string lastName;
int age;

string input;

cout << "Please enter your characters first and last name, as well as their age." << endl;

cin >> firstName >> lastName;
cin >> age;

cout << "Name: " << firstName << " "
<< lastName << endl;

cout << "Age: " << age << endl;

cout << "You dream a great storm and a voice speaking to you it whispers your doom on the salt winds.\n It speaks of a way to escape such a fate, but, before you are able to grasp how you are awakened by a loud clash of lightning.\n" << endl;
cout << "You awaken among the splintered remains of a crashed ship on a island, where you don't know.\n You look north and see what appears to be a castle, to the south a forest with smoke coming from the trees, possibly a camp, to the east and west there is only a vast ocean.\n" << endl;
cout << "Do you go to the north towards the castle, the south towards the camp, or attempt to swim away to the east or west?" << endl;

cin >> input;
if (input=="north")
{
cout << "You head towards the castle and find a guard, you ask him kindly where you are as he violently charges towards you saying you are trespassing on private lands.\n Do you attempt to run away or fight the guard?" << endl;
}else if (input=="south")
{
cout << "You head towards the camp to the south and find what appears to be a band of slavers, you see a woman tied in chains she notices you and attempts to signal for you help.\n Do you attempt to fight the slavers and help her or try to escape before they notice you?" << endl;
}else if (input=="east")
cout << "You attempt to swim through the eastern waters in an attempt to escape the island but quickly drown under the violent waters and storm." << endl;
else if (input=="west")
cout << "You find a raft on the western side of the jetty and attempt to repair it, in the make-shift raft you try to sail away from the island but it quickly tears apart in the violent waters and tears you under it, as you drown." << endl;
text-based rpg game? that would take ages to finish using if else statements. o_O
A text-based adventure game gets its data from two sources: the game script, and the user.

The game script will tell your program what to do: what to print, when to accept input, how to manipulate variables (if there are any), etc. Basically, you need to design a language and your program will be the interpreter. A game script could look like this:

location000:"in front of a bar"
print "You're ",__location_name,". You hear etc., etc., etc. <Poetic image>"
user
if command=="go" then
if direction=="north" then
goto location001
else if direction=="south" then
goto location002
else if direction=="east" then
goto location003
else if direction=="west" then
goto location004
else
goto location000
endif
//...
location001:"inside the bar"
print "You're ",__location_name
user
//And so on

Why is this necessary? Think of the script as a sort of macro file. You could write all that in C++, but it would take a really, really, really long time.

Then there's user input. It's traditional that text-based adventures recognize some form of natural language. Instead of presenting the user with menues, you let the user type what they want. This of course means that you must be able to understand them, and for that, you need another parser.
For example, a user might type "go west", "drink beer", "put coin in jukebox", "hit bartender with cue on pool table", etc. The parser must be able to tell commands, objects, and, shall we say, operators. For example: "go", "drink", "put", and "hit" are commands; "west", "beer", "coin", "jukebox", "bartender", "cue", and "pool table" are objects; and "in", "with", and "on" are operators.
Topic archived. No new replies allowed.