I am currently making a text based game, need help with "Choices"

Hello, I am new to programming, and just started making a C++ text based game today.
I encountered a problem where when you make a decision, the decision doesn't work, so you have to pick a new one, but the problem is, I don't know how to write the code for it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  	printf( "What do you do?\n");
	printf( "1. Open door with bare hands\n");
	printf( "2. Kick the door\n");
	printf( "3. Lick the door\n");
	printf( "4. Shoulder push the door\n)");
	
	printf( "Well? 1-4: ");
	scanf_s( "%d", &Choice );

	if( Choice == 1 )
	{
		printf( "You tried to open the door, but your hands suck dick.\n");
		printf( "Try something else?\n");
	}
	else if( Choice == 2 )
	{
		printf( "You kicked the door with your feet and legs\n");
		printf( "The door broke open and revealed the outside\n");
	}

On choice one, after "try something else?", I want to make it so that it displays the choices again to the user after he has chosen choice 1. How would I do this?

thanks..

If there is any more information that you need from me, please let me know.
Last edited on
And what about other choices? What are their behaviours?
What you probably want is a loop, with a flag that indicates whether to keep looping or not. For each value of Choice, you can set the flag to true or false, depending on whether you need to display the options again, or whether to break out of the loop and continue through the code.
@MikeyBoy, do you think you can give an example using C++? Preferably on my script?
I'm not MikeyBoy, but:
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 dooropen=false;
while (!dooropen) // shorthand for if something is false
{
  	printf( "What do you do?\n");
	printf( "1. Open door with bare hands\n");
	printf( "2. Kick the door\n");
	printf( "3. Lick the door\n");
	printf( "4. Shoulder push the door\n)");
	
	printf( "Well? 1-4: ");
	scanf_s( "%d", &Choice );

	if( Choice == 1 )
	{
		printf( "You tried to open the door, but your hands suck dick.\n");
		printf( "Try something else?\n");
	}
	else if( Choice == 2 )
	{
		printf( "You kicked the door with your feet and legs\n");
		printf( "The door broke open and revealed the outside\n");
                dooropen=true; // flag to break the while loop.
	} 
}


Alternatively, you could just add "break" to the code when you want to get out of the loop, I prefer to have my code contextual though.
Last edited on
Thank you so much @manudude03!
And out of Curiosity, what does the line "bool dooropen=false;" do?
bool is a value that can be true or false. he just created a bool called dooropen, and assigned the value "false" to it.

Ah, okay thanks!
Topic archived. No new replies allowed.