Choose Your Own Adventure C#

Running into some issues with my code that I’m unsure where I’m going wrong. The hints aren’t that helpful and there’s no video walkthrough like in some of the other lessons. Was hoping someone could take a look at my code and help guide?

Thank you. The error I can’t stop getting is : Error CS 8641 - Else cannot start a statement

CYA Code and I just can’t figure out where it’s coming from.

else if always has to be after an if or another else if.

else if can’t be after an else.

I copied your code into my project, and after several changes got it working. You have issues with how your if ... else, if ... else if ... else blocks are nested. You also are missing a pair of () following a method call to Console.ReadLine in one case, and have a couple of instances where you have a ; at the end of your if(condition to test) statement. The semi-colon following the if condition immediately prior to the else throwing the error is the cause of that error. I’m including your code here with my changes. It would be best if you only refer to it after trying to find all of these issues on your own. You may need to re-read some of the instructions to get the nesting corrected. It is very helpful to be consistent with indentation especially when dealing with multiple nested if ... else if ... else statements.

      Console.Write("What is your name?: ");
      string name = Console.ReadLine();
      Console.WriteLine($"Hello, {name}! Welcome to our story.");
      Console.WriteLine("It begins on a cold rainy night. You're sitting in your room and hear a noise coming from down the hall. Do you go investigate?");
      Console.Write("Type YES or NO: ");
      string noiseChoice = Console.ReadLine().ToUpper();
      if (noiseChoice == "NO")
        Console.WriteLine("Not much of an adventure if we don't leave our room!");
        Console.WriteLine("THE END.");  
      else if (noiseChoice == "YES")
        Console.WriteLine("You walk into the hallway and see a light coming from under a door down the hall.");
        Console.WriteLine("You walk towards it. Do you open it or knock?");
        Console.Write("Type OPEN or KNOCK: ");
        string doorChoice = Console.ReadLine().ToUpper();
        if (doorChoice == "KNOCK")
          Console.WriteLine($"A voice behind the door speaks. It says,\"Answer this riddle: Poor people have it. Rich people need it. If you eat it you die. What is it?");
          Console.Write("Type your answer: ");
          string riddleAnswer = Console.ReadLine().ToUpper();
          if (riddleAnswer == "NOTHING")
            Console.WriteLine("The door opens and NOTHING is there.");
            Console.WriteLine("You turn off the light and run back to your room and likc the door.");
            Console.WriteLine("THE END.");
            Console.WriteLine("You answered incorrectly. The door doesn't open.");
            Console.WriteLine("THE END");
        else if (doorChoice == "OPEN")
          Console.WriteLine("The door is locked! See if one of your three keys will open it.");


Good luck && happy coding!

Got it, thank you for your help

Thank you for taking the time to do that!

A lot of what you mentioned I found as i retraced my steps! I understand what you’re saying about the nesting of my if…else if…else statements. It helps A LOT to see it written, how you did it, thank you.

1 Like


I’ve attempted to do this with your corrections and it doesn’t allow the

else if (doorChoice == “OPEN”)
Console.WriteLine(“The door is locked! See if one of your three keys will open it.”);

to be at the bottom, this throws several errors.
If I place it after the doorChoice == “KNOCK” statement, it works fine, but doesn’t end the game after choosing “KNOCK” and proceeds to ask for a number (1-3)

I’ve tried to amend it as written above by midlindner, however it still doesn’t work for me.

Perhaps I’m being a tad stupid.