title: Else If condition given precedence over while condition?
body: <p>Please excuse this beginner's question. I've just started programming and I'm using C for the code below. </p>
  
  <p>The purpose of this code is for the computer to guess a number the user has picked. The computer will narrow down the numbers available based on queues like 'too low' or 'too high'. </p>
  
  <pre><code>computer_guess(int answer)
  {
      int lownum, highnum, guess, answer;
  
      //Instructions
      printf("Please use 'h' for too high or 'l' for too low ");
      printf("for incorrect guess. Use 'c' if the guess is right.\n");
  
      guess = (lownum + highnum)/2;
      printf("\n %d. \n", guess);
      printf("Is this the right number?");
  
      do
      {
          answer = getchar();
  
          if (answer == 'h') 
          {
              guess = (lownum + (highnum -1))/2;
              printf("%d \n", guess);
          }
  
          else if (answer == 'l') //If the computer's guess is too high.
          {
              guess = ((lownum + 1) + highnum)/2;
              printf("%d \n", guess);
          }
  
          else if (answer != '\n')//If the user enters letters other than 'h' or 'l', an error message will be returned.
          {
              fflush(stdin);  
              printf("Invalid. Please use either h (too high), l (too low) or c (correct).");
          }
  
      } while (answer != 'c');
  
      if (answer == 'c')//If the correct answer is given, the game will end.
      {
          printf("The computer has guessed the right number.");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The problem I'm running into is that my code seems to ignore my while condition (while (answer != 'c')). In my output, even if I enter 'c', it prints the Error statement in the last "else if" block and statement about being right. </p>
  
  <p>This is the output:   </p>
  
  <pre><code> Invalid. Please use either h (too high), l (too low) or c (correct). The computer has guessed the correct answer!
  </code></pre>
  
  <p>What do I need to do to make sure the error isn't printed when 'c' is entered? </p>
  
  <p>Thank you!</p>