snakeBite() function is not displaying anything?

Hey there, i'm relatively new and do use practices that are frowned upon since i'm still green to coding in general. However, I was curious if anyone could help me. In the following code, i'm trying to complete a short text base adventure with a health system, but one function is just not working. I've tried looking online and browsing separate forums, yet can't seem to figure out what i'm doing wrong. Please review the following code and let me know if any of you can help me out.

The function in question is snakebite() near the bottom. When I run the program and get to that function; the console just skips to the very end of said function and nothing is displayed.

I'm currently coding in Visual Studio 11 I believe.

Any help will be immensely appreciated.

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  void gameStart()
{
	int door = 0;
	int hp = 3;
	
	cout << "Once inside a dark aura envelopes the room." << endl;
	cout << "and a shiver runs down your spine." << endl << endl;

	system("Pause");
	system("Cls");

	cout << "Amidst the darkness, you can make out three doors." << endl;
	cout << "Each of these doors omit a subtle sound." << endl << endl;

	system("Pause");

retryDoors:

	system("Cls");

	cout << endl;

	cout << "Door 1: 'appears to be a hissing noise'" << endl;
	cout << "Door 2: 'sounds like wind flowing'" << endl;
	cout << "Door 3: 'is completely silent'" << endl << endl;

	cout << "Which do you choose?   "; cin >> door;

	switch (door)
	{

		case 1:
		{
			system("Cls");

			cout << "You slowly creek the door open and the hissing becomes louder." << endl;
			cout << "a snake lunges through the doorframe and bites you!" << endl;

			system("Pause");
			system("Cls");

			int snakeBite(int hp);

			system("Pause");

			goto retryDoors;

		}
		case 2:
		{
			cout << "The draft behind this door leads you to discover a hidden staircase" << endl;
			cout << " that leads you into the second floor." << endl << endl;

			int floor2(hp);
		}
		case 3:
		{
			cout << "Upon opening this door, you notice that its just an empty closet." << endl << endl;
			cout << "'Well this was helpful...' you think to yourself." << endl << endl;
			cout << "You proceed to turn back close the door." << endl << endl;

			system("Pause");
			system("Cls");

			break;
		}

		default:
		{
			cout << "This door doesn't exist..." << endl << endl;
			cout << "Please select a number from 1 - 3" << endl << endl;

			system("Pause");
			system("Cls");

			break;
		}

	}

}

int snakeBite(int x)
{
	int y = 0;
	
	y = (rand() % 2) + 1;
		
	if (y == 2);
	{
		cout << "You attempt to remove the poison, but weren't able to get all of it..." << endl << endl;
		cout << "You slam the door shut, however you feel noticably weaker..." << endl << endl;

		x - 1;

		system("Pause");
		system("Cls");

		return x;
	}
	
	cout << "You remove the snake and its poson and stumble back into the lobby." << endl << endl;

	system("Pause");

	return x;
}
int snakeBite(int hp);

Is that how you call a function? Or is that how you declare one?
@Zaq

You are declaring a function on lines 42 and 54, NOT calling them. To call a function, just use
snakeBite(hp); or floor2(hp);.

But, the variable 'hp' will not be changed doing so. One way to let hp change, would be..
hp = snakeBite(hp);.

Another thing, line 94 is incorrect. To reduce x, you write it as x = x - 1; or it could be written as x-=1; which is understood by the compiler to be 'x equals x minus one' same as previous example.
Last edited on
EDIT: Nevermind I see what you mean. Apologies if this subject was moreso trivial.

Thank you Cire
Last edited on
I see @whitenite1, thank you for your help clearing up some of this for me. The program is running the way it should as far as the functions go. As for the "Line 94" thank you for pointing that out! That would have went right over my head.

You have been a great help!


Also, that hp = snakebite(hp). Should I place this where I'm calling it?
(Line 42?)
Last edited on
@Zaq

Also, that hp = snakebite(hp). Should I place this where I'm calling it?
(Line 42?)


Yes

As an aside, using goto is really frowned on, as can make for what is called, 'spaghetti code'. It's better to use a while loop
line 17..
do {

A line 80..
while(door!=2);

and change line 46 to break;

Topic archived. No new replies allowed.