If/Else Statements Are Not Working

When i run the program if i enter north/south it will just go to the system("pause"). can someone help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  int main(){
	char direction [6];
	char action [10]; 

	cout<<"################################################################################";
	cout<<"#                                                                              #";
	cout<<"#                           Beast's Text Adventure                             #";
	cout<<"#                                                                              #";
	cout<<"################################################################################";
	cout<<"\n\n\n\n";
	cout<<"You are in a dark room, you cant see anything except some light shining from \nsome doors.\nThere is two doors. One to the north. One to the south.";
    cout<<"\n\nWhere do you want to move? ";
	cin>>direction;
	  if (direction == "north"){
		  cout<<"It leads to another room. This room is lighter then the last. You can make out a lightswitch to the left of you.";
		  system("pause");
	  }else if (direction == "south"){
		  cout<<"There some light breaking through some red velvet curtains.";
	  }
		system("pause");
	return 0;
}
Last edited on
This expression

if (direction == "north"){

is always false because the address of array direction is not equal to the address of string literal "north".
To compare strings you should use standard C function strcmp declared in header <cstring>

For example

if ( std::strcmp( direction, "north" ) == 0 ){
// and so on
Topic archived. No new replies allowed.