title: C++ Random number guessing game
body: <p>I have to write a program that will run a random guessing game. The game is to be numbers from 1-100, the guesser gets 20 tries and at the end is supposed to be asked if they would like to play again. There also has to be multiple options for print outs if the guesser is to high or low. I have part of my program done I know I still need to add the other options for print outs but right now my issue is that when I try to run what I have it says successful but then there is an error that says that the variable "number" is being used without be initialized. I am not sure what to do to get it initialized apparently. (I am new to C++)
  <strong>I have updated my program and am now having a different issue.  My program runs but if the guess is lower than the number it prints Too high try again and Too lower try again but when the number is too high it just prints Too high try again.  I also noticed that when the user chooses to play again the tries counter is not resetting with the game.  One last thing I have to add more messages for when they win, lose and are asked to play another game and I have to use random number to choose among them. SO any advice on the best route to do that would be great</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt; 
  #include &lt;ctime&gt;
  using namespace std;
  char chr;
  
  int main()
  {
  srand(time(NULL));                                           //the function that generates random numbers
  int number=rand()%100+1;                                     //the range of the random numbers
  int guess;                                                   //The guess is stored here
  int tries=0;                                                 //The number of tries stored here
     char answer;                                                 //The answer to the question is stored here
  answer='y';                  
  
  while(answer=='y'||answer=='Y') 
  {
      while (tries&lt;=20 &amp;&amp; answer=='y'|| answer=='Y')
      {
      cout&lt;&lt;"Enter a number between 1 and 100 "&lt;&lt;endl;          //The user is asked for a guess
      cin&gt;&gt;guess;                                               //The guess is stored here
      tries++;                                                 //Adding a number for every try
      if(guess==0||guess&gt;100)                                  //If statement that produces an error message if user enters a number out of the peramiters
      {
       cout&lt;&lt;"This is not an option try again"&lt;&lt;endl;          //Error message
      }
  
      if(tries&lt;20)                                            
      cout&lt;&lt;"Tries left: "&lt;&lt;(20-tries)&lt;&lt;endl;                   //Output to let the user know how many guess they have left
  
      if(number&lt;guess);                                         //if the guess is to high
      cout&lt;&lt;"Too high try again"&lt;&lt;endl;                         //This message prints if guess it to high
  
      if(number&gt;guess)                                          //if the guess is to low
      cout&lt;&lt;"Too low try again"&lt;&lt;endl;                          //This message prints if the guess is to low
  
      if(number==guess)                                          //If the user guesses the number
      {
       cout&lt;&lt;"Congratualtions!! "&lt;&lt;endl;                          //Message printed out if the user guesses correctly
       cout&lt;&lt;"You got the right number in "&lt;&lt;tries&lt;&lt;" tries"&lt;&lt;endl;  //Lets the user know how many guess they used
       answer = 'n';
      }
      if(tries &gt;= 20)                                               //If the user uses all their guesses
      {
      cout &lt;&lt; "You've run out of tries!"&lt;&lt;endl;                      //The message that prints when a user is out of guesses
      answer='n';
      }
      if(answer=='n')
      {
       cout&lt;&lt;"Would you like to play again?  Enter Y/N"&lt;&lt;endl;       //asking if play would like to play again
       cin&gt;&gt;answer;                                                  //Store users answer
       if (answer=='N'|| answer=='n')                                //if the user says no
       cout&lt;&lt;"Thanks for playing!"&lt;&lt;endl;                            //This message prints out if they choose not to play again
  
      else
          number=rand()%100+1;                                        //This starts the game over if they choose to play again
      }
  
      }
      }
  
  cin&gt;&gt;chr;
      return 0;
  
  }
  </code></pre>