Well I'm writing a text adventure in C++ (Cause they are easy to do, to a point) and I'm having a problem, I have used goto (yes, its a bad habit I know, just using it till I find an easier way) to make my code reverse itself so it automatically displays one of the sections that's needed to advandce the story right after a section is shown. This leads to using goto to et out, but it always messes up, it automatically closes. Heres my rather messy code for the section that it screws up on:
switch ( inn1 ){
case 1:
inn11:
cout << "\nAfter waiting for the receptionist, eventually an old hag appears. Sho appears ";
cout << "to have burn marks on her body. She says to you in an old crackling voice:\n";
cout << "'Yes sir? Would you like a room? It's completely free.'\n";
cout << "Do you reply:\n1.Yes, I would like a room\n2.No, i would not like a room\n>";
cin >> speak1;
goto speak1;
case 2:
cout << "\nThe newspaper is dated a few years back. It shows a report of a fire that only ";
cout << "happened... yesterday?! How could it be? This is an old newspaper, yet it shows ";
cout << "a fire from yesterday? Even the date on the article shows yesterday! You throw ";
cout << "the newspaper on the desk and start waiting for the receptionist.\n";
goto inn11;
case 3:
cout << "\nYou look in the box and find a Revolver with 6 bullets. You take it and load it ";
cout << "before looking around in the box. After a short while you find a holster and ";
cout << "attach it to your belt. You place the gun in your holster and wait for the ";
cout << "receptionist to come.\nWeapon Obtained: Revolver\nRevolver Ammo +6\n";
revolver = 1;
revolverammo = 6;
goto inn11;
default:
cout << "That isn't a choice.Pick again";
cin >> inn1;
}
speak1:
switch ( speak1 ){
case 1:
cout << "\nYou get the key to your room and instructions on how to get it. You head upstairs";
cout << "and enter it. you close the door and suddenly you feel a strange drowsyness come";
cout << "upon you. You suddenly topple over onto the bed and fall asleep, however, you ";
cout << "don't wake up. did you ever think to read the number on your key, 13...";
cout << "\nYou have died, Game Over...";
goto end;
case 2:
cout << "\nYou refuse her offer and she suddenly grabs a key from the shelf and tries to ram";
cout << "into your hand. After a short struggle you shove her backwards and she topples ";
cout << "over into a cupboard which drops on her. You hear a crack as her skull is split ";
cout << "open. You go to walk out but you hear groaning behind you. You turn to see the ";
cout << "woman stood behind the desk, she slowly shambles towards you, groaning madly\n";
cin.ignore();
if ( revolver = 1 ){
cout << "You quickly move your hand to the revolver in your holster and draw it out. You ";
cout << "aim at her head and attempt to steady your hand. Do you wish to fire at her, even";
cout << "with your hand shaking slightly? [Y]es or [N]o?\n";
cin >> fight1;
}
default:
cout << "That isn't a choice.Pick again";
cin >> speak1;
}
end:
cin.ignore();
return EXIT_SUCCESS;
The section that meses up is the first 'case' of inn1, whenever you enter 1 for your choice, the next section doesn't appear, even though there is an cin.ignore() at the end of the code. I just tested it with a cin.ignore() in the main code, after 'You have died...' and it works fine, but taking away the 'goto end' and the cin.ignore in the end makes it show case 2 aswell.
What I want to know is why it messes up, it shouldn't mess up, should it? Or is it all goto's fault *waves fist at goto*