title: scanf not working on invalid input
body: <p>On a character input in the first <code>scanf()</code>, the second one doesn't run. <code>getchar()</code> isn't working either for Try Again input. It skips to take input for  <strong>Would you like to play again? (Y/N)?</strong> It seems that <code>your_choice</code> is supposed to take the character and check it afterward but the character is actually being taken by <code>ch</code>. What is causing it to work like this and how to resolve the issue. I've tried re-initializing the variables but doesn't work.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void choice(int);
  
  int main() {
      char ch;
      int random, your_choice;
  
      do {
          srand(time(NULL));
          system("cls");
          printf("** 0 is for Rock **\n");
          printf("** 1 is for Scissors **\n");
          printf("** 2 is for Lizard **\n");
          printf("** 3 is for Paper **\n");
          printf("** 4 is for Spock **\n");
  
          printf("\nEnter your choice here:");
          scanf("%d", &amp;your_choice);
  
          random = rand() % 5; //random number between 0 &amp; 4
          if ((your_choice &gt;= 0) &amp;&amp; (your_choice &lt;= 4)) {
              //choice printer omitted for this post
  
              if ((random == ((your_choice + 1) % 5)) || (random == ((your_choice + 2) % 5)))
                  printf("\n\n... and you win!!!\n");
              else if ((random == ((your_choice + 3) % 5)) || (random == ((your_choice + 4) % 5)))
                  printf("\n\n... and you lose!!!\n");
              else if (random == your_choice)
                  printf("\n\nUnfortunately, it's a tie!\n");
          } else
              printf("\nWell, this is wrong! Try again with a number from 0 to 4!!\n");
  
          printf("\nWould you like to play again? (Y/N)?: ");
          scanf(" %c", &amp;ch);
  
      } while (ch == 'y' || ch == 'Y');
  
      return 0;
  }
  </code></pre>