Making a Textspace game and commands don't work!

I made this code and the commands (if statements) do NOT work. Please help!

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <string.h>

int main () {
	char userInput[]="o";
	char name[30]="Blank";
	char cont[2] = "i";
	char quit[2] = "q";
	char con[2] = "c";
	char north[] = "north";
	char south[] = "south";
	char west[] = "west";
	char east[] = "east";
	char help[] = "help";
	char b[] = "b";
	char l[] = "l";
	char d[] = "d";
	char j[] = "j";
	char p[] = "p";
	char sd[] = "sd";
	char patch[] = "patch";
	char peek[] = "peek";
	char crouch[] = "crouch";
	char challenge[] = "challenge";
	int i = 0;
	printf("Please type in your name:");
	scanf("%s", name);
	printf("Hello, %s. Welcome to Adam's textspace game! Type c to continue, and q to quit.\n", name);
	while(i==0){
	scanf("%s", &cont);

	printf("\nNow, the story begins...\n\nYou appear stranded in a desert, and have been dehydrated for two days. You must find water, shelter, and/or a way out of the desert. Press L to look around and HELP for help.\n\n");
	while ((strcmp(userInput, l) == 0)){
	scanf("%s", &userInput);
	if (strcmp(userInput, help) == 0) printf("Type in NORTH for NORTH, SOUTH for SOUTH, EAST for EAST, and WEST for WEST.\n\n");
	if (strcmp(userInput, l) == 0) printf("\nYou look around...\nTo the north is a small puddle of water, to the east is a lake that appears to have ridges appearing over the water, to the south is just a bunch of rocks, and to the west is a cave.\n\n");
	if (strcmp(userInput, north) == 0) printf("\nYou go north towards the puddle of water, and take a look. It seems dirty, but still edible.\n Press D to drink, or SOUTH to go back south.");
	if (strcmp(userInput, d) == 0) printf("\nYou drink the water and feel refreshed, but you start gagging. Press G to gag, or J to swallow.");
	if (strcmp(userInput, j) == 0) printf("\nYou swallow, and you figure out that you gagged because of your dry throat. You feel good. Press B to go back south.");
	if (strcmp(userInput, b) == 0) printf("\nYou move south, back to your previous location. To the west is a cave, to the east is a lake, now with no ridges, and to the south is still just a bunch of rocks.");
	if (strcmp (userInput, south) == 0) printf("\nYou see rocks, lots of them. Type NORTH to go NORTH, and P to pick the rocks up.");
	if (strcmp (userInput, north) == 0) printf("\nYou go back to your previous location and look back at the rocks. You see fire-ants crawling on them, and you feel thankful you didn't pick them up. To the west is a cave, and to the east is the lake.");
	if (strcmp (userInput, east) == 0) printf("\nYou go east, towards the lake. Nothing dangerous is visible, and it seems safe to swim and drink from. Press SD to swim and drink from the lake, and BACK to go back to your previous location.");
	if (strcmp (userInput, sd) == 0) printf("\nYou take a drink from the lake, then jump in. You have so much hydration that it's almost like you are NOT in a desert, but then, clouds start to form. You better find shelter! Type EAST to go to the cave, and SOUTH to go to the rocks.");
	if (strcmp (userInput, south) == 0) printf("\nYou go to the rocks, and check for ants. None appear. Type P to pick up rocks, or BACK to go back to your previous location.");
	if (strcmp (userInput, p) == 0) printf("\nYou pick up the rocks and go to the cave, and you see a shadow in the distance. It appears to be a hyena! You quickly hide in the cave, and make a life/death decision Type PATCH to close the cave with the rocks, or CHALLENGE to fight the hyena with the rocks.");
	}
	if (strcmp (userInput, patch) == 0) printf("\nYou peek outside, and see a ranger with a gun. You instantly jump from the rocks and shout that you need help. The ranger brings you to the city, where you get a job and become a successful businessman.\n\nThe End.");
	if (strcmp (userInput, challenge) == 0) printf("\nYou challenge the hyena, and see another one coming by. You throw the rock, but realize the hyena is a ranger. You are then under federal arrest for assault.\n\nThe End.");


	if(strcmp(cont,quit) == 0){
		i = 1;
	}
	else{
		i = 0;

	}
	
		
}
}
Have you tried declaring the "commands" as strings instead of char arrays?
On line 33 you have a while statement that compares the userInput to l but before that you dont ever have a scanf that puts anything into userInput. userInput at that part of the program is always just "o". Therefore the while loop is never entered and your if statements are not tested. I modified the program to work in a more proper way where the if statements are tested.
Here is the modified 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

#include <stdio.h>
#include <string.h>

int main () {
	bool in = false;
	char userInput[]="o";
	char name[30]="Blank";
	char cont[2] = "i";
	char quit[2] = "q";
	char con[2] = "c";
	char north[] = "north";
	char south[] = "south";
	char west[] = "west";
	char east[] = "east";
	char help[] = "help";
	char b[] = "b";
	char l[] = "l";
	char d[] = "d";
	char j[] = "j";
	char p[] = "p";
	char sd[] = "sd";
	char patch[] = "patch";
	char peek[] = "peek";
	char crouch[] = "crouch";
	char challenge[] = "challenge";
	int i = 0;
	printf("Please type in your name:");
	scanf("%s", name);
	printf("Hello, %s. Welcome to Adam's textspace game! Type c to continue, and q to quit.\n", name);
	scanf("%s", &cont);
	while(i==0){


	printf("\nNow, the story begins...\n\nYou appear stranded in a desert, and have been dehydrated for two days. You must find water, shelter, and/or a way out of the desert. Press L to look around and HELP for help.\n\n");
	scanf("%s", &userInput);
	while ((strcmp(userInput, l) == 0) || (strcmp(userInput, help) == 0) || in == true){

		in = true;
	
	if (strcmp(userInput, help) == 0) printf("Type in NORTH for NORTH, SOUTH for SOUTH, EAST for EAST, and WEST for WEST.\n\n");
	if (strcmp(userInput, l) == 0) printf("\nYou look around...\nTo the north is a small puddle of water, to the east is a lake that appears to have ridges appearing over the water, to the south is just a bunch of rocks, and to the west is a cave.\n\n");
	if (strcmp(userInput, north) == 0) printf("\nYou go north towards the puddle of water, and take a look. It seems dirty, but still edible.\n Press D to drink, or SOUTH to go back south.");
	if (strcmp(userInput, d) == 0) printf("\nYou drink the water and feel refreshed, but you start gagging. Press G to gag, or J to swallow.");
	if (strcmp(userInput, j) == 0) printf("\nYou swallow, and you figure out that you gagged because of your dry throat. You feel good. Press B to go back south.");
	if (strcmp(userInput, b) == 0) printf("\nYou move south, back to your previous location. To the west is a cave, to the east is a lake, now with no ridges, and to the south is still just a bunch of rocks.");
	if (strcmp (userInput, south) == 0) printf("\nYou see rocks, lots of them. Type NORTH to go NORTH, and P to pick the rocks up.");
	if (strcmp (userInput, north) == 0) printf("\nYou go back to your previous location and look back at the rocks. You see fire-ants crawling on them, and you feel thankful you didn't pick them up. To the west is a cave, and to the east is the lake.");
	if (strcmp (userInput, east) == 0) printf("\nYou go east, towards the lake. Nothing dangerous is visible, and it seems safe to swim and drink from. Press SD to swim and drink from the lake, and BACK to go back to your previous location.");
	if (strcmp (userInput, sd) == 0) printf("\nYou take a drink from the lake, then jump in. You have so much hydration that it's almost like you are NOT in a desert, but then, clouds start to form. You better find shelter! Type EAST to go to the cave, and SOUTH to go to the rocks.");
	if (strcmp (userInput, south) == 0) printf("\nYou go to the rocks, and check for ants. None appear. Type P to pick up rocks, or BACK to go back to your previous location.");
	if (strcmp (userInput, p) == 0) printf("\nYou pick up the rocks and go to the cave, and you see a shadow in the distance. It appears to be a hyena! You quickly hide in the cave, and make a life/death decision Type PATCH to close the cave with the rocks, or CHALLENGE to fight the hyena with the rocks.");

	scanf("%s", &userInput);
	}
	if (strcmp (userInput, patch) == 0) printf("\nYou peek outside, and see a ranger with a gun. You instantly jump from the rocks and shout that you need help. The ranger brings you to the city, where you get a job and become a successful businessman.\n\nThe End.");
	if (strcmp (userInput, challenge) == 0) printf("\nYou challenge the hyena, and see another one coming by. You throw the rock, but realize the hyena is a ranger. You are then under federal arrest for assault.\n\nThe End.");


	if(strcmp(cont,quit) == 0){
		i = 1;
	}
	else{
		i = 0;

	}
	
		
}
}


Heres what I get:

Please type in your name:Abid
Hello, Abid. Welcome to Adam's textspace game! Type c to continue, and q to quit
.
c

Now, the story begins...

You appear stranded in a desert, and have been dehydrated for two days. You must
 find water, shelter, and/or a way out of the desert. Press L to look around and
 HELP for help.

help
Type in NORTH for NORTH, SOUTH for SOUTH, EAST for EAST, and WEST for WEST.

l

You look around...
To the north is a small puddle of water, to the east is a lake that appears to h
ave ridges appearing over the water, to the south is just a bunch of rocks, and
to the west is a cave.

north

You go north towards the puddle of water, and take a look. It seems dirty, but s
till edible.
 Press D to drink, or SOUTH to go back south.
You go back to your previous location and look back at the rocks. You see fire-a
nts crawling on them, and you feel thankful you didn't pick them up. To the west
 is a cave, and to the east is the lake.


As you can see the program still isnt working as expected. Heres a hint you have multiple strcmp to north and to south so mutliple ifs will be true with a single north input. You need to have a state variable that tells the program where the player is. Is he at the rocks? then only test certain if conditions. Is he at the puddle of water then only test these certain conditions etc.. Thats how I'd go about it.


Last edited on
Topic archived. No new replies allowed.