title: Random number game C
body: <p>The game works fine my first time through, although; the second time it only gives you two lives... I have tried to change the number of lives but still can't figure out what I'm doing wrong.</p>
  
  <blockquote>
    <p>// C_program_random_number_game</p>
  </blockquote>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;time.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
  
     srand(time(NULL));
     int num1,x = 0;
     char game, cont, replay;
  
     printf("Would you like to play a game? : ");
     scanf("%c",&amp;game);
  
    if (game == 'y' || game == 'Y')
    {
      printf("\nThe rules are simple. You have have 5 tries to guess the computers number. \n \n If you succeed you win the game, if you dont you lose the game. Good luck!");
      do
      {
          int r = rand()%5 +1;
          printf("\n\nEnter a number between 1 and 5 : ");
          scanf("\n%d",&amp;num1);
          x++;
          if(num1 &gt; 0 &amp;&amp; num1 &lt; 5)  
          {
  
              do
              {
               if(num1 &lt; r)
                  {
                      printf("\nClose! try a little higher... : ");
                      x++; 
                  }
                else if (num1 &gt; r)
                  {
                      printf("\nClose! try a little lower...: ");
                      x++; 
                  }
                  scanf("%d",&amp;num1);
  
              }while(num1!=r &amp;&amp; x &lt;3); 
  
              if(num1 == r) 
              {
                  printf("\nWinner! &gt;&gt; you entered %d and the computer generated %d! \n",num1, r);
              }
              else if(num1 != r)
              {
                  printf("\nBetter luck next time!");
              }
              printf("\n\nWould you like to play again? (y or n) : ");
              scanf("\n%c",&amp;replay);
          }
              else
          {
              printf("Sorry! Try again : ");
              scanf("%d",&amp;num1);
          }
  
      }while(replay == 'y'|| replay == 'Y');
  
  }
  else if (game == 'n' || game == 'N')
  {
      printf("Okay, maybe next time! ");
  }
  else
  {
      printf("Sorry, invalid data! ");
  }
  return 0;
  </code></pre>
  
  <p>}</p>