Choose Your Own Adventure

hello i would like to ask you how to do such thing that if a user chooses no no how to make the program no longer execute the code and the program will end. because now after selecting the condition “no”, pressing the button continues the program and reads the following conditions and asks for “knock or poen”. (sorry for my english) :):relaxed:

"$ dotnet run
What is your name?: ramas
Hello, ramas! Welcome to our story.
It begins on a cold rainy night. You’re sitting in your room a
nd hear a noise coming from down the hall. Do you go investiga
Type YES or NO
Not much of an adventure if we don’t leave our room!


Hello, @object4146271593.

Welcome to the forums.

Consider a structure like this:

if(answer == "YES")
  //continue game
  //game over

Update: I just looked back at the project. The instructions ask you to write an if statement to see if the user entered NO, so your structure would be more like this:

if(answer == "NO")
  //game over
  //continue game
  //your next choice and remaining choices would be inside this block

You’d do that differently depending on how you’ve structured your code.

As an example, your game might be made out of components that have to be scheduled to run, ending the game could then be done by not scheduling a next thing to happen.

A simpler but more abrupt way of ending would be to terminate the process. This denies other parts of your code the chance to clean up/finish, but if your program really isn’t doing anything else that may be completely fine.
In python that would be done with

import sys
print("this doesn't print")

Or haskell:

import System.Exit (exitSuccess)
main = putStrLn "bye!" >> exitSuccess >> putStrLn "this doesn't print"

You’d have to find the equivalent in C#