Text adventure game

Hello I need help with a text adventure game but the code is to long to put here, how can I get around that to post it to get help?
Is it necessary to post the entire code? What is the specific problem you are having?
Chances are that the whole code is not wrong. Only a small portion of your code is probably wrong.

Save a copy of your code, and then work on shaving down your code so that you can get rid of every thing that is not related to the bug -- i.e. produce the smallest, most straight-forward program you can that still reproduces the bug. This is a vital technique to debugging that will often cause you to find the bug, but at the very least make it easier for others to debug.

https://stackoverflow.com/help/mcve
http://sscce.org/
Last edited on
Hello I'm trying to make it to where there are choices and when you make one it will take you to the correct function in order for the code to run. However I can't find a way to make it where I don't get an error of undeclared function regardless of how i order it. Please help, note this is not the full 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
string userOption;
int userMainMenu;
int userChoice;
int userChoice4;
int userChoice2;
int userChoice3;
int userChoice5;
int userChoice9;
int userChoice8;
int userChoice10;
void alternateKicktheWall() {
cout << "You search around the entire room, finally with a bit of luck you see a few bricks in the back that a lose. Possibly that is an exit.";
    cout << "What would you like to do?" << endl;
    cout << "1. Scream for help again" << endl;
    cout << "2. Try to kick in the wall." << endl;
    cout << "3. Cry." << endl;
    cin >> userChoice5;

        switch (userChoice5) {
        case 1:
            alternatescreamForHelp();
        break;
        case 2:
            cout << "You kick the wall with all of your might, it budges slightly, enough for you too see through the wall. On the other side lies what looks like a tunnel." << endl;
            cout << "What would you like to do" << endl;
            cout << "Scream for help again." << endl;
            cout << "Try to kick the wall again!" << endl;
            cout << "Cry. " << endl;
            cin >> userChoice10;
        break;
        case 3:
            crylikeaBabyScene();
        break;
        }


}
void screamforHelpScene2() {
    cout << "THE GAURD COMES BACK BRUH" << endl;

}
void crylikeaBabyScene() {

cout << "You cry" << endl;
}

void alternatescreamForHelp() {
        cout << "You hear someone running towards you as you scream bloody murder. A gaurd comes around the corner and yells 'What the hell is wrong with you" << endl;
            cout << "What would you like to say?" << endl;
            cout << "Why am I here?" << endl;
            cout << "1. Where am I?" << endl;
            cout << "2. Ask both" << endl;
            cout << "3. Remain silent" << endl;
            cin >> userChoice9;


            switch (userChoice9) {
            case 1:
                cout << "The guard looks at you and says 'Ha! How should I know, I'm just the guard doing my job, now shut up or you'll wish you were somewhere else'" << endl;
                cout << "The guard walks away laughing at you." << endl;
                cout << "What would you like to do?" << endl;
                cout << "1. Scream for help again" << endl;
                cout << "2. Try to kick in the wall" << endl;
                cout << "3. Cry" << endl;
                cin >> userChoice8;

            break;
            case 2:
                cout << "You're in the city of Velven. Now quite down before I make you quite!" << endl;
                cout << "What would you like to do?" << endl;
                cout << "1. Scream for help again." << endl;
                cout << "2. Try to kick in the wall." << endl;
                cout << "3. Cry." << endl;
                cin >> userChoice8;
            break;
            case 3:
                cout << "You're in the city of Velven, but how should I know why you're here, I'm just doing my job! Now quite down." << endl;
                cout << "What would you like to do?" << endl;
                cout << "1. Scream for help again." << endl;
                cout << "2. Try to kick in the wall." << endl;
                cout << "3. Cry." << endl;
                cin >> userChoice8;
            break;
            default:
                cout << "That is not an option please try again." << endl;
                cin >> userChoice8;
            }
            switch (userChoice4) {
            case 1:
                screamforHelpScene2();
            break;
            case 2:
                alternateKicktheWall();
            break;
            case 3:
                crylikeaBabyScene();
            break;


        }


}




void kickWallScene1() {
    cout << "You search around the entire room, finally with a bit of luck you see a few bricks in the back that a lose. Possibly that is an exit.";
    cout << "What would you like to do?" << endl;
    cout << "1. Scream for help." << endl;
    cout << "2. Try to kick in the wall." << endl;
    cout << "3. Cry." << endl;
    cin >> userChoice5;

        switch (userChoice5) {
        case 1:
            alternatescreamForHelp();
        break;
        case 2:
            cout << "You kick the wall with all of your might, it budges slightly, enough for you too see through the wall. On the other side lies what looks like a tunnel." << endl;
            cout << "What would you like to do" << endl;
            cout << "Scream for help." << endl;
            cout << "Try to kick the wall again!" << endl;
            cout << "Cry. " << endl;
            cin >> userChoice10;
        break;
        case 3:
            crylikeaBabyScene();
        break;
        }

}

void screamForHelpScene1() {



            cout << "You hear someone running towards you as you scream bloody murder. A gaurd comes around the corner and yells 'What the hell is wrong with you" << endl;
            cout << "What would you like to say?" << endl;
            cout << "1.Why am I here?" << endl;
            cout << "2. Where am I?" << endl;
            cout << "3. Ask both" << endl;
            cout << "4. Remain silent" << endl;
            cin >> userChoice3;


            switch (userChoice3) {
            case 1:
                cout << "The guard looks at you and says 'Ha! How should I know, I'm just the guard doing my job, now shut up or you'll wish you were somewhere else'" << endl;
                cout << "The guard walks away laughing at you." << endl;
                cout << "What would you like to do?" << endl;
                cout << "1. Scream for help again" << endl;
                cout << "2. Look for a way out of the cell." << endl;
                cout << "3. Cry" << endl;
                cin >> userChoice4;

            break;
            case 2:
                cout << "You're in the city of Velven. Now quite down before I make you quite!" << endl;
                cout << "What would you like to do?" << endl;
                cout << "1. Scream for help again." << endl;
                cout << "2. Look for a way out of the cell." << endl;
                cout << "3. Cry." << endl;
                cin >> userChoice4;
            break;
            case 3:
                cout << "You're in the city of Velven, but how should I know why you're here, I'm just doing my job! Now quite down." << endl;
                cout << "What would you like to do?" << endl;
                cout << "1. Scream for help again." << endl;
                cout << "2. Look for a way out of the cell." << endl;
                cout << "3. Cry." << endl;
                cin >> userChoice4;
            case 4:
                cout << "'Hah, that's what I thought, not even able to get a word out, pathetic.' The guard then walks away laughing. " << endl;
                cout << "What would you like to do?" << endl;
                cout << "1. Scream for help again." << endl;
                cout << "2. Look for a way out of the cell." << endl;
                cout << "3. Cry." << endl;
                cin >> userChoice4;
            break;
            default:
                cout << "That is not an option please try again." << endl;
                cin >> userChoice4;
            }

        switch (userChoice4) {
            case 1:
                screamforHelpScene2();
            break;
            case 2:
                alternateKicktheWall();
            break;
            case 3:
                crylikeaBabyScene();
            break;


        }



}
I think you may want to look at function prototyping...

http://www.cplusplus.com/articles/yAqpX9L8/
So all I need to do is declare it at the beginning and it will go find it? Just clarifying.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
// prototype your functions
void myfun1();
void myfun2();
void myfunc3();

int main()
{
   ...
   return 0;
}

// define your functions here, or anywhere as long as it's not above the function
// prototypes, and they can be called pretty much anywhere in the program.


So all I need to do is declare it at the beginning and it will go find it?

So yeah, pretty much. Declare it as a prototype, and you can call it whenever.
Topic archived. No new replies allowed.