title: Random Number Guessing Game Answers 0
body: <p>I am creating a random number guessing game where the user sets the maximum number they want to guess from. I have figured out most of the code, the problem that I seem to be getting is that after setting the maximum number and beginning to guess the answer is always 0. Any tips on how to adjust my code so that the answer is a number within the range and not 0? </p>
  
  <pre><code>class Program
  {
  
      public static int SelectedNumber = 0;
      public static Random ran = new Random();
      public static bool GameOver = false;
      public static int UserMaxValue = 0; 
      public static string decision;
  
      static void Main(string[] args)
      {
  
          int UserNumber;
          SelectedNumber = ran.Next(0, UserMaxValue);
  
          do
          {
              Console.WriteLine("What is the maximum number you want to guess from?");
              UserMaxValue = Convert.ToInt32(Console.ReadLine());
  
              do
              {
                  Console.WriteLine("Select a number between 1 and {0}!", UserMaxValue);
                  UserNumber = Convert.ToInt32(Console.ReadLine());
                  GuessNumber(UserNumber);
              } while (GameOver == false);
          } while (GameOver == false);
      }
  
      public static void GuessNumber(int UserNumber)
      {
  
          if (UserNumber &lt; SelectedNumber)
              Console.WriteLine("Your number is wrong, please try again!");
          else if (UserNumber &gt; SelectedNumber)
              Console.WriteLine("Your Number is wrong, please try again!");
          //else if (UserNumber == 0)
          //    Console.WriteLine("Your Number is wrong, please try again!");
          else
          {
              Console.WriteLine("Yay! You got the right number. Do you want to play again? (y/n) ", decision);
              decision = Console.ReadLine();
  
              if (decision == "n")
                  GameOver = true;
              else
                  do
                  {
                      Console.WriteLine("What is the maximum number you want to guess from?");
                      UserMaxValue = Convert.ToInt32(Console.ReadLine());
  
                      do
                      {
                          Console.WriteLine("Select a number between 1 and {0}!", UserMaxValue);
                          UserNumber = Convert.ToInt32(Console.ReadLine());
                          GuessNumber(UserNumber);
                      } while (GameOver == false);
                  } while (GameOver == false);
              }
          }
      }
  }
  </code></pre>