title: For loop guessing game in C
body: <p>a program to get the user to guess the number that the program has picked as the lucky number. It uses one for loop and plenty of if statements. The problem is that my code stops after 2 tries, but suppose to give user 3 tries. Here is what I have so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  int main()
  {
      int iSecret, iGuess;
      srand(time(NULL));
      iSecret = rand() % 20 + 1;
      int tries = 0;
  
      printf("\nWelcome to the number guessing game!\nFor each game, you have at most 3 chances to guess a secret number from 1 to 20.\n");
  
      for (tries = 0; tries &lt; 3 || iSecret == iGuess; tries++)
      {
          printf("Please, enter a number between 1 and 20!   ");
          scanf("%d", &amp;iGuess);
  
          if (iGuess == iSecret)
          {
              printf("\nCongratulations! You won!");
              return 0;
          }
  
          else if (iGuess &gt; iSecret)
          {
              tries++;
              printf("\nYour guess was too high.\n");
          }
  
          else if (iGuess &lt; iSecret)
          {
              tries++;
              printf("\nYour guess was too low.\n");
          }
          if (tries == 3)
              break;
      }
  
      printf("\nYou have reached your third trials. The correct number is %d.\n",
              iSecret);
      return 0;
  }
  </code></pre>