I know it's something I'm doing wrong, but I can't seem to figure out what it is. The console reads the text you input and replies to what you have sent with a message set specifically for your input message. When I input "hello", it replied with "Hello! How are you? (Answers = good, bad)", but when I go to enter either "yes" or "no", the console closes without submitting the message I've specified. Can anybody help me out?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3 {
  class TestClass1 {
    static void Main() {
      String UserInput = Console.ReadLine();
      String PrevAnswer = null;

      switch (PrevAnswer) {
        case null: {
          switch (UserInput) {
            case "hello": {
              Console.WriteLine("Hello! How are you? (Answers = good, bad)");
              break;
            }

            case "goodbye": {
              Environment.Exit(0);
              break;
            }
          }
          break;
        }

        case "hello": {
          switch (UserInput) {
            case "good": {
              Console.WriteLine("That's good to hear");
              Console.ReadLine();
              break;
            }

            case "bad": {
              Console.WriteLine("Oh, that's sad to hear :(");
              break;
            }
          }
          break;
        }
      }
      Console.ReadLine();
    }
  }
}

At first glance it looks like you're missing a loop. As it is the code only runs through once. Here's a simple way to use a loop:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
    class TestClass1
    {
        static void Main()
        {
            bool Continue = true;
            string UserInput = "";
            String PrevAnswer = null;
            while (Continue)
            {
                switch (PrevAnswer)
                {
                    case null:
                        {
                            UserInput = Console.ReadLine();                            
                            switch (UserInput)
                            {
                                case "hello":
                                    {
                                        Console.WriteLine("Hello! How are you? (Answers = good, bad)");
                                        break;
                                    }
                                case "goodbye":
                                    {
                                        Console.WriteLine("Goodbye\nPress any key to exit.");
                                        Continue = false;
                                        break;
                                    }
                            }
                            break;
                        }
                    case "hello":
                        {
                            UserInput = Console.ReadLine();                            
                            switch (UserInput)
                            {
                                case "good":
                                    {
                                        Console.WriteLine("That's good to hear");    
                                        break;
                                    }
                                case "bad":
                                    {
                                        Console.WriteLine("Oh, that's sad to hear :(");
                                        break;
                                    }
                            }
                            break;
                        }
                    default:
                        Console.WriteLine("Goodbye\nPress any key to exit.");
                        Continue = false;
                        break;
                }
                PrevAnswer = UserInput;
            }
            Console.ReadKey();
        }
    }
}
Comments
Thanks for this mate.
This question has already been answered. Start a new discussion instead.