title: Forcing user to enter an Integer using a While loop in C
body: <p>I am trying to get the user to enter a integer to be later used in the program I want it to force user to enter an input until it is an integer. When I run this code it goes on an infinite loop like so:</p>
  
  <blockquote>
    <p>Enter smallest operator: Enter smallest operator: Enter smallest operator: Enter smallest operator: Enter smallest operator: Enter smallest operator:..........</p>
  </blockquote>
  
  <p>I think the issue is with the scanner but I am unsure as to how I should approach it. </p>
  
  <pre><code>    #include &lt;stdio.h&gt;
  #include &lt;ctype.h&gt;
  
  int main(int argc, const char * argv[]) {
  
      char operator;
      int largestOpperator, smallestOpperator;
  
      printf("Enter The Table Operator (+, -, *, /, %%, or R): ");
      scanf("%c",&amp;operator);
  
      /*while(!(operator == '+' || operator == '-' || operator == '*' || operator == '/' ||operator == '%' || operator == 'R'))
      {
  
          printf("Enter Appropriate Table Operator (+, -, *, /, %%, or R): ");
          scanf(" %c",&amp;operator); //requires space as a way to skip the enter when char is scanning!!
      }*/
  
      do{
          if(!isdigit(smallestOpperator))
              printf("Enter smallest operator: ");
          else{
              printf("Enter an actual number: ");
              scanf(" %d", &amp;smallestOpperator);
          }
  
      }while(!isdigit(smallestOpperator));
  
  
      printf("Enter largest operator: ");
      scanf("%d", &amp;largestOpperator);
  
      {
          printf("Enter a valid integer: ");
          scanf("%d", &amp;largestOpperator);
      }
  
  
      return 0;
  }
  </code></pre>