bool AskChoice(string chapter, int& a)
{
int choice;
map<string,string>::iterator Iter;
Iter = Chapters.find(chapter);
if (Iter == chapters.end())
{
cout << "Incorrect Chapter";
returnfalse;
}
cout << Chapters[chapter];
choice = readkey();
a = choice;
returntrue;
}
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.
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!!