Text Adventure issue

I am working on a text adventure right now, and it's pretty good if I do say so myself. But right now there is one big issue that continues to vex me. Help would be appreciated!

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
34
35
36
37
38
39
40
41
42
43
44
45
46
a = 0;
	b = 5;

	while (a > 5)
	{
  if (answer5 == "2")                                                              //this is if answer is 2
  { cout << "You die from being really fat and your fat suffocates you."<<endl; 
    Sleep (4 * 1000);
		a = 1;
		b = 500;
		while (a < b)
	{ cout << "-  -    -      - -  -    -  - -   -     -       -   -    -   - -    -  -";
		a = a + 1; } 
		system("CLS");
		cout << "YOU DIED";
		Sleep (4 * 1000);
		system("CLS");
		cout << "Would you like to restart?"<<endl;
		cin >> answer1;

		if ( answer1 == "yes" || answer1 == "Yes")
		{ goto  Beginning; }
		
		else if (answer1 == "no" || answer1 == "No")
			{ return 0; }
  }


  else if (answer5 != "1" || answer5 != "2")
			{ cout << "Did you read the instructions? Either you didn't read the instructions or your just plain stupid."<<endl;  //security protocol if someone doesnt answer yes or no
		Sleep (4* 1000);                                                                                                          //need to add it throughout program
		return 0; }
	


  else if (answer5 == "1")  //this is if answer is 1 (CORRECT)
  {   system("CLS");
	  goto yes1; }        
    
	

  Sleep(2 * 1000);
  a = a + 1;
  if (a >= 5)
  {goto timerunout;}
	}


The problem is that I don't know how to make the program go to the time run out.
I assume (but might be wrong) that the program would go through this whole portion until until either 'option 1' or 'option 2' was entered or 'a' became equal to 5.

This isn't my whole text adventure, just the part that gives me trouble. So
all the 'gotos' and answer5 are taken care of outside of this portion of the program. Thanks for any help.
Last edited on
Never, and I repeat NEVER use goto statements in C++. It is one of the worst coding practices. It wil make your program difficult to read, and likely lead to errors
put line 36 (the whole if statement with { }) after line 26.

the if statement on line 29 is always true and can be removed
@ats15

I disagree, I think it's best to give the programmer as much freedom as possible. goto is perhaps the only native non-conditional jump. Even tho I use it extremely rarely, it still is something that is in the language for a reason.

@Jace

I suggest not listening to people who say "NEVER use X!", or "ALWAYS use Y!". There is no need for borderline syndrome. C++ gives us a lot of freedom, no matter how dangerous, let's get comfortable with it. In your code tho, I don't think your gotos are well justified. Instead of saying goto Beginning;, you can set a boolean flag and check for that flag, or call a function. In this case the goto will probably lead to spaghetti code.
You're right; you should never say never.

Instead, let's say this: "goto" statements are so dangerous, and do so much damage to code maintainability, that the only people who should ever use them are experts. In fact, the only people who should ever use them are those who are expert enough to know other, better ways to structure their code.
Last edited on
I'm pretty sure your program will go through the if/else statements first, wait two seconds, and then do stuff with a. For methods running at the same time, you need to use threads--which I do not know, so I cannot explain to you how it works.

Also:

You die from being really fat and your fat suffocates you.
...or your just plain stupid.

To me, you lost the right to call the player stupid. No offense. :(

Edit:
Depending on how you're getting the player's input for answer5, you could implement a counter variable.
Last edited on
Topic archived. No new replies allowed.