Text game

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
string sytnaxengine(string syntax)
{
	if (syntax == "north","n") {syntax = "gon";}
	else if (syntax == "south","s") {syntax = "gos";}
	else if (syntax == "west","w") {syntax = "gow";}
	else if (syntax == "east","e") {syntax = "goe";}
	else if (syntax == "up","u") {syntax = "gou";}
	else if (syntax == "down","d") {syntax = "god";}
	else if (syntax == "examine","look around","look","check room","examine surroundings") {syntax= "examine";}
	else if (syntax == "invenvtory","check inventory","items") {inventory(syntax);}
	else if (syntax == "where am I?","what room am I in?","where am i?","what room am i in?","where am i","what room am i in","check room","room") {roomcheck(syntax);}
	return syntax;
};

//begin program
int actmain()
{
	string x = "";
	cin >> x;
	x = sytnaxengine(x);
	if (x == "gon") {cout << "you go north";}
	else if (x == "gos") {cout << "you go south";}
	else if (x == "gow") {cout << "you go west";}
	else if (x == "goe") {cout << "you go east";}
	return 0;
};


im trying to make a text game and i want it to return different text for different inputs but right now it only outputs "you go north"
if (syntax == "north","n") should be if ( syntax == "north" && syntax == "n" )
( and so the others )
&& is the C++ operator meaning and

http://www.cplusplus.com/doc/tutorial/operators/
Last edited on
I believe Bazzy meant that if (syntax == "north","n") should be if ( syntax == "north" || syntax == "n" ) where || is the logical or operator. And, yes, it is a good idea to check out the link he suggests.
Last edited on
Yes, sorry
Thank you i was hung up on that for sooo long lol and ive already been through the tutorials lol

edit: it still doesnt work lol even with this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
string sytnaxengine(string syntax)
{
	if ( syntax == "north" || "n" ) {syntax = "gon";}
	else if ( syntax == "south" || "s" ) {syntax = "gos";}
	else if ( syntax == "west" || "w" ) {syntax = "gow";}
	else if ( syntax == "east" || "e" ) {syntax = "goe";}
	else if ( syntax == "up" || "u" ) {syntax = "gou";}
	else if ( syntax == "down" || "d" ) {syntax = "god";}
	else if ( syntax == "examine" || "look around" || "look" || "check room" || "examine surroundings" ) {syntax= "examine";}
	else if ( syntax == "invenvtory" || "check inventory" || "items" ) {inventory(syntax);}
	else if ( syntax == "where am I?" || "what room am I in?" || "where am i?" || "what room am i in?" || "where am i" || "what room am i in" || "check room" || "room" ) {roomcheck(syntax);}
	return syntax;
};

//begin program
int actmain()
{
	string x = "";
	cin >> x;
	x = sytnaxengine(x);
	if ( x == "gon" ) {cout << "you go north";}
	else if ( x == "gos" ) {cout << "you go south";}
	else if ( x == "gow" ) {cout << "you go west";}
	else if ( x == "goe" ) {cout << "you go east";}
	return 0;
};
Last edited on
closed account (jwC5fSEw)
That's because you didn't actually use the code they gave you.
lol yay it finally works and yes the output is correct
Topic archived. No new replies allowed.