Choose Your Own adventure help

Hello! I am having trouble figuring out what is wrong with my code here. one of the errors that I am receiving is telling me it is expecting a ; at the end of my switch. Any hints as where to look would be appreciated.

using System;

namespace ChooseYourOwnAdventure
{
class Program
{
static void Main(string args)
{
/* THE MYSTERIOUS NOISE */

  // Start by asking for the user's name:
  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 investigate?");

  Console.WriteLine("Type YES or NO:");
  string noiseChoice = Console.ReadLine();

  //makes user input UPPERCASE
  string upperNoiseChoice = noiseChoice.ToUpper();

  if (upperNoiseChoice == "NO")
      {
        Console.WriteLine("Not much of an adventure if we don't leave our room!");
        Console.WriteLine("THE END.");

      }
      
  else if (upperNoiseChoice == "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.WriteLine("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:\"");
      Console.WriteLine("\"Poor people have it. Rich people need it. If you eat it you die. What is it?\"");
      Console.WriteLine("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 lock the door.");
        Console.WriteLine("THE END.");
      }

      else if (doorChoice == "OPEN")
      {
        Console.WriteLine("You answered incorrectly and the door doesn't open.");
        Console.WriteLine("THE END.");
      }
  }


  else if (doorChoice == "OPEN")
  {
      Console.WriteLine("The door is locked! See if one of you three keys will open it.");
      Console.Write("Enter a number (1-3):");
      string keyChoice = Console.ReadLine().ToUpper();
      //string upperKeyChoice = keyChoice.ToUpper();

      Switch (keyChoice)
        {
          case "1":
            Console.WriteLine("You choose the first key. Lucky Choice!");
            Console.WriteLine("The door opens and NOTHING is there. Strange...");
            Console.WriteLine("THE END");
            break;

          case "2":
            Console.WriteLine("You choose the second key. THe door doesn't open.");
            Console.WriteLine("THE END.");
            break;

          case "3":
            Console.WriteLine("You choose the second key. THe door doesn't open.");
            Console.WriteLine("THE END.");
            break;
            
          default:
            Console.WriteLine("Incorrect input the story ends here...");
            break;
        }
  }

      }
}

}
}

// You wrote:
Switch (keyChoice)

// It should be:
switch (keyChoice)

// You wrote:
string doorChoice = Console.ReadLine().ToUpper;

// It should be:
string doorChoice = Console.ReadLine().ToUpper();

// You wrote:
string riddleAnswer = Console.ReadLine().ToUpper;

// It should be:
string riddleAnswer = Console.ReadLine().ToUpper();
2 Likes

Dang, thank you very much I knew it had to be something simple.

This is the kind of think that I’d write a ton of little helper functions for, once I saw the patterns forming. e.g.

string GetUserResponse(string prompt, bool upper = true) {
    Console.Write(prompt);
    var result = Console.ReadLine() ?? "";
    return upper ? result.ToUpper() : result;
}

You should be able to do all of this with switches. Make sure you tell you user when then enter junk. Or, you could offer them a menu and force them to select valid options, thus clamping down on just before the switch.

You’re also going to get real deep in the switches real quick. Consider moving your depth out into other functions.

Good luck and have fun.