I need to know how to jump around in my code to be able to do something sort of like this:
You start in room A
you have the choice of going to room B
In room B you will have the option to go back to room A or continue to another room, etc etc.
this is what i have been given so far but i get an error.
you recieved an error because you defined the roomA(); and roomB(); functions inside int main();.
you should put that outside of "main"
int main(int argc, char *argv[])
{
roomA();
roomB();
}
void roomA() ------------------------>Also leave out the ; during function definition
{
cout << "You are in room A" << endl;
cin >> choice;
if ( choice == "roomB" )
{
roomB();
}
void roomB() ------------------------> Also leave out the ; during function definition
{
cout << "You are in room B" << endl;
cin >> choice;
if ( choice == "roomA" )
{
roomA();
}
}
And about jumping around in code, you can use the goto(); function but... you already are jumping from function to other function with that code you scripted. Its alot better than goto();. So your set.
I found it, wowww int main(int argc, char *argv[],void roomA(), void roomB())
i
i was messing around trying to figure it out on my own :P those dont belong there...
And about jumping around in code, you can use the goto(); function but... you already are jumping from function to other function with that code you scripted. Its alot better than goto();. So your set.
Don't use goto...it's definitely not needed in this situation.
Also, the way you have it, if someone goes back and forth between room a and b, your program will eventually crash due to recursion. I'd suggest making a variable like "current place" that stores the room, then call the appropriate function for that room, which would then return the next area to go to.