title: How do I fix this random number generation code in C for my class?
body: <p>I'm a beginner in C programming and i would appreciate if i could get some tips on how to set a program to restart? I'm currently building a guessing game, where the user has 4 attempts to guess the secret number which is provided randomly. I have almost completed the code, but it does not run correctly and some of the things it returns are incorrect. Please help.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  int main() {
    int a, Thenumber, GuessNumber, NumberofTries = 4, theAnswer;
    time_t ti;
    printf(&quot;Welcome to the game. \nI am going to choose any number between 10 and 30&quot;);
    printf(&quot;\nYou must try to guess the number. If you guess incorrect, I will tell you if you were too high or too low&quot;);
    printf(&quot;\nYou will have 4 attempts to guess the number.\n&quot;); 
  
    srand((unsigned)time(&amp;ti));
    Thenumber = rand() % 1 + 3 + 1;//10+20+1;4
  
    for (NumberofTries = 0; NumberofTries &lt; 4; NumberofTries++) {
      printf(&quot;\n \nPlease enter a number:&quot;);
      scanf(&quot;%d&quot;, &amp;GuessNumber);
      if (GuessNumber &gt; 30) {
        printf(&quot;That is illegal. Your number can only be between 10 and 30. Please enter a number between those numbers:/n&quot;);
  
      }
      else if (GuessNumber &gt; Thenumber) {
        printf(&quot;I'm sorry, that is too high. \n&quot;);
      }
    }
  
    if (GuessNumber &lt; Thenumber) {
      printf(&quot;I'm sorry, that is too low. \n&quot;);
    }
  
    else if (GuessNumber == Thenumber) {
      printf(&quot;You are correct. Do you want to continue playing? y-yes n-no:  \n&quot;);
      return 0;
    }
  
    printf(&quot;\n \nI'm sorry, you have no more attempts.\n \nDo you want to play again? y-yes n-no: \n&quot;);
    scanf(&quot;%d&quot;, &amp;theAnswer);
  
    if ((theAnswer = 'n')) {
      printf(&quot;Goodbye, thank you for playing. Please play again soon.&quot;);
    }
    return 0;
  }
  </code></pre>