Arrays

Hello, This is a part of my first project in c++.
My question is how I can make the program read everything in the array, not only the first word wich my friend said was the fault.
Sadly he couldn't help me with a solution.
The debugger says that "tunnelchoice" isn't declared.
Thanks in advance and I hope i have formulated my question correctly.

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

string tunnelchoice1[2] = {"wide", "the wide tunnel"};
string tunnelchoice2[2] = {"high", "the high tunnel"};
string tunnelchoice3[2] = {"low", "the low tunnels"};

 void tunnels()
{

	while(gameIsRunning) {	
		cout << "Which tunnel do you wish to enter?" << endl;
		cout << "The wide, the small or the low tunnel?" << endl;
		cin >> tunnelchoice;

		if(tunnelchoice == tunnelchoice1) {
		cout << "You walked right in the right tunnel" << endl;
		cin.get();
		cout << "The way gets dark after walking for a bit" << endl;
		cin.get();
		cout << "The road gets dark and you cant see the ground" << endl;
		cin.get();
		cout << "Suddenly you feel that the ground loosens and you find yourself fallin down" << endl;
		cin.get();
		system("cls");	
		cout << "***************************************************************************************************" << endl;
		cout << "****************	                              	You are dead	            ****************" << endl;
		cout << "***************************************************************************************************" << endl;
		cin.get();
		exit(EXIT_FAILURE);
		}
		
		if(tunnelchoice == tunnelchoice2) {

		}


What the code outputs:

1
2
3
4
5
6
7
8
9
projectRpgFunctions.cpp: In function 'void tunnels()':
projectRpgFunctions.cpp:193:10: error: 'tunnelchoice' was not declared in this scope
   cin >> tunnelchoice;
          ^~~~~~~~~~~~
projectRpgFunctions.cpp:193:10: note: suggested alternative: 'tunnelchoice3'
   cin >> tunnelchoice;
          ^~~~~~~~~~~~
          tunnelchoice3

Last edited on
what line declares the variable tunnelchoice ? (hint: there isnt one).
This is your problem. You have used similar names over and over and forgot to make this one.

also, save your own sanity, your grade, and your friendship all in one swoop:
don't get help from your friends if they are not already much better coders than YOU are. If he is 2 classes ahead of you, sure, ... if he did not know this (its a basic error message, tells exactly what and where the problem is) he can't help you right now and you should not ask again until you are both farther along. There will be a day when you can really give good advice to each other. But not for a while.

Last edited on
Hello Davidoff,

On lines 14 and 31 you compare "tunnelchoice" to "tunnelchoice?", but "tunnelchoice?" is a two element array, so which element are you comparing to?

Lines 2 - 4 appear to be global variables. Even if they are not it would be a good idea to precede these definitions with "const" to make them constant so that you do not accidentally change their values. Unless another part of the program would need to change them, but I do not feel that this should happen.

Hope that helps,

Andy
Topic archived. No new replies allowed.