title: Letter Guessing Game in C
body: <p>The error I got was that the number of game wasn't shown correctly. 
  For example, I chose to play 2 games. I, then, tried to guess the first number correctly. The solution was shown and then jumped to the next game. However, the second game was shown as Game 3 instead of Game 2. 
  I tried again. This time, I guessed the letter 1 time incorrectly and 1 time correctly. After the second guess, the game showed the solution and then stopped the game despite me choosing to play 2 games and only 1 game was played. 
  The order of letters in LetterList file is 
  d
  B
  G
  w
  Q
  t
  r
  Y
  u
  X
  So the first game starts with 'd' and then 'B' and then etc....
  The error was shown as if the program itself got rid of even numbers. 
  I don't know what was wrong with it.</p>
  
  <pre><code>#define _CRT_SECURE_NO_WARNINGS
  #include &lt;stdio.h&gt;
  #include &lt;ctype.h&gt;
  #define MAXGUESSES 5
  
  
  void LetterGuessRules();
  void GuessTheLetter(char);
  char GetTheGuess();
  int CompareLetters(char, char);
  
  int main()
  {
      FILE *inPtr;
      int numGames, i = 0;
      char letter;
  
      //display the game rule
      LetterGuessRules();
  
      printf("\nHow many games do you want to play? (Max 10) &gt;&gt; ");
      scanf("%d", &amp;numGames);
      printf("\n\n************************************************\n");
      inPtr = fopen("letterList.txt", "r");
  
      for (i = 0; i &lt; numGames; i++)
      {
          //get a solution letter from file - use fscanf
          fscanf(inPtr," %c", &amp;letter);
          //change the solution to lowercase
          letter = tolower(letter);
          //print the solution back onto the screen to test
  
          //Close this when play the game to hide the foreseen solution
          printf("\nThe letter is %c\n", letter);   
  
          //Number of match
          printf("\t\tGame %d\n", i += 1);
  
          //call the GuessTheLetter function and pass it the solution
          GuessTheLetter(letter);
      }
      fclose(inPtr);
      return 0;
  }
  
  void GuessTheLetter(char letter)
  {
      int win = 0;
      int numGuesses = 0;
      char myGuess;
  
      while (numGuesses &lt; MAXGUESSES &amp;&amp; win == 0)
      {
          //get a guess from the user  by calling the GetTheGuess function
          myGuess = GetTheGuess();
  
          //change the guess to lowercase
          myGuess = tolower(myGuess);
  
          //win = call the function to compare the guess with the solution
          win = CompareLetters(letter, myGuess);
  
          numGuesses++;//count the number of guesses so far
  
          //use conditions to let the user know if they won or lost the round of the game
          if (win == 0)
          {
              printf("\nOops its wrong.\n");
              if (myGuess &lt; letter)
              {
                  printf("Your guessed letter -%c- comes before the solution\n", myGuess);
                  printf("Please guess again :)\n");
              }
              else if (myGuess &gt; letter)
              {
                  printf("Your guessed letter -%c- comes after the solution\n", myGuess);
                  printf("Please guess again :)\n");
              }
              if (numGuesses == MAXGUESSES &amp;&amp; win == 0)
                  printf("Aw you have lost this game!");
                  printf("\n");
          }
          else if (win == 1)
          {
              printf("\nYou have guessed it right!\n");
              printf("Wonderful! You ACE'd this match!\n");
              printf("\n");
              printf("**** If you play more than 1 game, new match will automatically start ****\n");
              printf("\tYou only need to keep guessing for the next letter\n");
              printf("------------------------------------------------------------------------------");
              printf("\n");
          }
      }
  }
  
  char GetTheGuess()
  {
      char myGuess;
      printf("\t_______________________");
      printf("\n\t|What's your guess? &gt;&gt; "); 
      scanf(" %c", &amp;myGuess);
  
      return myGuess;
  }
  
  void LetterGuessRules()
  {
      printf("\n*** Instruction: ");
      printf("\nYou will have 5 attempts to guess the right answer");
      printf("\nIf you guess it right, the game will end with your victory.");
      printf("\nOtherwise, you will have to guess again.");
      printf("\nPlease have fun!");
  }
  
  int CompareLetters(char letter, char myGuess)
  {
      if (letter == myGuess)
      {   
          return 1;
      }
      else
      {
          return 0;
      }
  }
  </code></pre>