title: rand() is generating the same number in guessing game
body: <p>Programming in C, I am trying to run a game where the computer generates a number between 1 and 100.  However, I keep getting 42 as the number generated... what is wrong with my "rand()"</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  int main (void)
  {
      int guess, tries = 6;
      int number = 1+(rand()%100);
  
      printf("Pick a number between 1 and 100:");
      scanf_s("%d", &amp;guess);
  
      while(tries &gt; 0 &amp;&amp; guess != number)
      {
          if(guess &gt; number)
              printf("Too high");
          else
              printf("Too low");
          puts(". Guess again:");
          scanf_s("%d",&amp;guess);
  
          tries--;
      }        
  
      if(guess == number)
          puts("You win!");
      else
          puts("You lose");
  }
  </code></pre>
  
  <p>after a good amount of discussion below I added in the fallowing lines of code</p>
  
  <pre><code>#include &lt;time.h&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>srand ((unsigned int)time(NULL));
  </code></pre>
  
  <p>but the code failed to run in MS visual studio until i googled the error and it turns out that MSVS needs the variebles to be declared at the top of each function/block.  after doing this the code works fine.  Thank you everyone and sorry for the multiple edits.  corrected code:</p>
  
  <pre><code>#include &lt;time.h&gt;
  int main (void)
  {
  int guess, tries = 6, number;
  srand ((unsigned int)time(NULL));
  number = 1+(rand()%100);
  </code></pre>
  
  <p>The rest is the same. Thank you all.</p>