title: How would I be able to make the program stop with only a specific input in C#
body: <p>I am very new to C# and I have just created my first program, which is your classic &quot;number guesser&quot;.</p>
  <p>In my program, after the user has guessed the correct number, I want to give them an option where they can either type &quot;Y&quot; or &quot;N&quot; to continue or end the game.</p>
  <p>Where my issue lies is, if the user were to type in the letter &quot;G&quot; at this stage, the program would continue and ask the user to input another number.</p>
  <p>How do I enable my code to keep looping at this stage until either Y is pressed to continue the game or N is pressed to end the program?</p>
  <pre><code>using System;
  
  // Namespace
  namespace NumberGuesser
  {
      // Main Class
      class Program
      {
          // Entry Point Method
          static void Main(string[] args)
          {
              GetAppInfo();   // Run GetAppInfo function to get info
  
              GreetUser();   // Ask for user's name and greet
  
              while (true)
              {
                  // Create a new Random object
                  Random random = new Random();
  
                  // Initial correct number
                  int correctNumber = random.Next(1, 11);
  
                  // Initial guess var
                  int guess = 0;
  
                  // Ask user for number
                  Console.WriteLine(&quot;Guess a number between 1 and 10:&quot;);
  
                  // While guess is not correct
                  while (guess != correctNumber)
                  {
                      // Get users input
                      string input = Console.ReadLine();
  
                      // Make sure it's a number
                      if (!int.TryParse(input, out guess))
                      {
                          // Print error message
                          PrintColourMessage(ConsoleColor.Red, &quot;Please user an actual number.&quot;);
  
                          // Keep going
                          continue;
   
                      }
  
                      // Make sure the number guessed is between 1 - 10
                      if (guess &gt; 10)
                      {
                          // Print error message
                          PrintColourMessage(ConsoleColor.Red, &quot;Please enter a number from 1 to 10.&quot;);
  
                          // Keep going
                          continue;
                      }
  
                      // Cast to int and put in guess
                      guess = Int32.Parse(input);
  
                      // Match guess to correct number
                      if (guess != correctNumber)
                      {
                          // Print error message
                          PrintColourMessage(ConsoleColor.Red, &quot;Wrong number, please try again.&quot;);
  
                      }
  
                  }
  
                  // Print success message
                  PrintColourMessage(ConsoleColor.Yellow, &quot;You are CORRECT!!!&quot;);
  
                  // Ask to play again
                  Console.WriteLine(&quot;Play again? [Y or N]&quot;);
  
                  // Get answer
                  string answer = Console.ReadLine().ToUpper();
  
                  if (answer == &quot;Y&quot;)
                  {
                      continue;
                  }
  
                  else if (answer == &quot;N&quot;)
                  {
                      return;
                  }
  
                  else
                  {
                      return;
                  }
  
                 
  
  
              }
          }
  
          // Get and display app info
          static void GetAppInfo()
          {
              // Set app vars
              string appName = &quot;Number Guesser&quot;;
              string appVersion = &quot;1.0.0&quot;;
              string appAuthor = &quot;Jack Thomas&quot;;
  
              // Change text colour
              Console.ForegroundColor = ConsoleColor.Green;
  
              // Write out app info
              Console.WriteLine(&quot;{0}: Version {1} by {2}&quot;, appName, appVersion, appAuthor);
  
              // Reset text colour
              Console.ResetColor();
          }
  
          // Ask user's name and greet
          static void GreetUser()
          {
              // Ask users name
              Console.WriteLine(&quot;What is your name?&quot;);
  
              // Get user input
              string inputName = Console.ReadLine();
  
              Console.WriteLine(&quot;Hello {0}, let's play a game...&quot;, inputName);
          }
  
          // Print colour message
          static void PrintColourMessage(ConsoleColor color, string message)
          {
              // Change text colour
              Console.ForegroundColor = color;
  
              // Prints message
              Console.WriteLine(message);
  
              // Reset text colour
              Console.ResetColor();
          }
  
      }
  
  }
  
  </code></pre>