Text based RPG, need help plz

hey guys, im working on a small text based RPG in C++. What im trying to do is have the user prompted with a question, like "Which direction would you like to travel", then the user enters West or w. What would be the best way to cade this? or can someone point me to some source code to look at.
cin??
yes im using cin, but i meant what is the best way to compare what they input to what i have in my code. What i want to do is have them enter a direction or a command and then have a IF statement like:


If (command != "west" || w)
cout << "Error unknown command;
else
cout << "you are traveling west";

But when i try this, and have their input saved in a variable like command, i keep getting an error C++ forbids the comparsion between a pointer and an integar.
I would do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
char direction;

cout <<"Enter the direction that you want to travel: ";
cin >> direction;

if (direction == 'w')
cout <<"You are moving west.\n";
	//and whatever other commands

else 
cout <<"Invalid command.\n";

  system ("pause");
what exactly does the system("pause") function do?
just keeps the DOS window from closing immediately. it prompts the user to press a key before the window closes
And this: http://www.cplusplus.com/forum/articles/11153/

For alternatives, read this: http://www.cplusplus.com/forum/beginner/1988/
Or you can use CodeBlocks and not worry about it, because it always pauses console applications after they terminate.

And it's not a DOS window, it's a console window.
baddasfadsiogunwjsdg i feel like a retard for saying DOS
No need for that, it's a common mistake.
How would i do it if i wanted the user to input two different commands but run the same code for either of them?
would this work?

char direction;

cout << "please enter a direction.";
cin >> direction;

if (direction == 'w' || 'west')
cout << "you are traveling west";
else
cout << "Error, unknown command";

I was trying to use the "!=" not equal too operator, but kept getting a compiler error,
can anyone tell me why this wouldnt work?


char direction;
cout << "Enter a direction";

if (direction != 'w' || 'west')
cout << "Your traveling west";
else
cout << "Unknown direction";





A char can be represented by a string but a string can not be represented by a char. In your example, you use single quotes to define a multi characer literal constant, you need to use double quotes. You also need to tell the compiler what to compare "west" against. So:

1
2
3
4
5
6
7
8
9
10
11
std::string direction; /*Change To std::string Datatype*/

char direction;

cout << "please enter a direction.";
cin >> direction;

if (direction == "w" || direction == "west") /*We Are Now Comparing Strings*/
cout << "you are traveling west";
else
cout << "Error, unknown command";
@Computergeek You seem to have redefined a variable. I assume you meant to remove the line
 
char direction;


Or were you just leaving it in for comparison?
No you are right, I didn't check my code before posting it.

@ OP: Remeber to leave out Line 3 when you try this. Thanks Xander314
sweet thank you so much compgeek01 that is eaxcatly what i needed, it works perfectly now.
yeah well in my CS class last week we went over the difference so i feel stupid haha
Topic archived. No new replies allowed.