title: Guessing Game using for loop with C# Corrected
body: <p>I have written the code for the following program:</p>
  
  <p>Inside the for loop block of code I need to perform the following logic:</p>
  
  <ol>
  <li>Display to the screen “Enter Guess #: “ (e.g. “Enter Guess 2: “ where # is the number of
  the guess the user is on). </li>
  <li>Get a number from the user and store the entered value in the input variable for testing.</li>
  <li>Convert “input” to an integer (int32) and store in “guess”.
  d. Determine whether the entered number, now stored in “guess”, is the correct answer and take one of the following actions:
  <ul>
  <li>Display “You Win” if entered value is the answer and exit the loop.</li>
  <li>Tell the user their guess is higher or lower than the answer.</li>
  </ul></li>
  <li>If the user is not able to guess the answer in 5 guesses, then display “You Lose”</li>
  </ol>
  
  <p>I getting an error with this code. Can anybody help me?</p>
  
  <pre><code>    int answer = 0, guess;
      string input = "" ;
      //Create an oject of the Random class
      Random number = new Random();
      answer = number.Next(1, 11);
  
  
  
      answer = number.Next(1, 11);
      Console.WriteLine("Select Randomly Number between 1 and 10 ");
   //   guess = (Convert.ToInt32(Console.ReadLine()));
      for (int i = 1; i &lt;=5; i++)
      {                
          Console.Write("Enter Guess :");
          guess = Convert.ToInt32(Console.ReadLine());
          if (guess &gt; answer)
          {
              Console.WriteLine("Guess is Higher");
          }
          else if (guess &lt; answer)
          {
              Console.WriteLine("Guess is Lower");
          }
          else
          {
  
              Console.WriteLine("You Won !!\t {0} is the correct number", guess);
              break;
              i = 6;
  
          }
      }
      Console.WriteLine("You Loose");
      Console.WriteLine("The answer is {0} ", answer);
      Console.ReadKey(); 
  </code></pre>