Having Problem in using a map

I was trying to make a simple Text based RPG in the console (I know the console isn't made for that,I am making it just for fun).

Now I was reading about maps from this site's reference and found that they can be very useful in the game.

Here is a part of the 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
bool AskChoice(string chapter, int& a)
{
	int choice;
	map<string,string>::iterator Iter;
	Iter = Chapters.find(chapter);
	if (Iter == chapters.end())
	{
		cout << "Incorrect Chapter";
		return false;
	}

	cout << Chapters[chapter];
	choice = readkey();	
	a = choice;
	return true;
}
int main ()
{
	map<string,string> Chapters;
			Chapters["Jail"] = "You wake up in a dark room. You see that there is a rusted door on your left & a Barred Window above you.";
			Chapters["Jail"] +=  "You decide to:\n1> Break open the door.\n2> Break Open the Window.\n";

//...
}


Now the problem is:
If I call AskChoice("Jail"), after the part I have posted above, it returns false and outuputs
Incorrect Chapter
.

But if I simply do this it works:
 
cout << Chapters["Jail"];


Any Help?

EDIT:
NOTE:If there a syntax error in this snippet, it is a error I made while re-typing it here. There is no syntax error in the actual code.
Last edited on
Well, you're declaring

map<string,string> Chapters;

as a local variable in main().

But this won't be visible to AskChoice() so, if you're code is compiling, there must be another (global) variable called Chapters above the code you posted.

Either 1. remove the local variable and always use the global. :-(
Or 2. remove the global and pass the variable to AskChoice() :-)
Thanks. There was re definition in my code! I just can't guess why didn't VS prompt me for it. It has dome so before.
Removing the Local on did the work though.
Thanks a Lot!!
Topic archived. No new replies allowed.