title: How to properly clear buffer for input (First Project) #rewritten code
body: <p>How do i proplerly clear input buffer since fflush(stdin) is undefined and only available in some compilers,</p>
  <p>My plan is to clear input since after looping back it still use the buffered input rather than getting a new input.</p>
  <p>Here is my code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  
  //bool function
  bool isInteger(double val)
  {
      int truncated = (int)val;
      return (val == truncated);
  }
  
  int main()
  {
      //local variable
      double result, a, b;
      char oper, option = 'y';
      
      //loop
      while(option == 'y')
      {
          system(&quot;cls&quot;);
          printf(&quot;Enter number and operator to solve:\n\nExapmple [a + b][a - b][a * b][a / b]\n&quot;);
          scanf(&quot;%lf %c %lf&quot;, &amp;a, &amp;oper, &amp;b);
          
          // nested if
          if(isInteger(a) &amp;&amp; isInteger(b))
          {
              if(oper == '+')
              {
                  result = a + b; //calculation
                  printf(&quot;%.1lf %c %.1lf = %.1lf\n\n&quot;, a, oper, b, result); //ouput result
              }
              else if(oper == '-')
              {
                  result = a - b; //calculation
                  printf(&quot;%.1lf %c %.1lf = %.1lf\n\n&quot;, a, oper, b, result); //ouput result
              }
              else if(oper == '*')
              {
                  result = a * b; //calculation
                  printf(&quot;%.1lf %c %.1lf = %.1lf\n\n&quot;, a, oper, b, result); //ouput result
              }
              else if(oper == '/')
              {
                  result = a / b; //calculation
                  printf(&quot;%.1lf %c %.1lf = %.1lf\n\n&quot;, a, oper, b, result); //ouput result
              }
              else
              {
                  //output error
                  printf(&quot;Invalid Operater!\n&quot;);
              }
          }
          else
          {
              //output error
              printf(&quot;Input is not a digit!\n&quot;);
          }
          //output selection
          printf(&quot;Do you want to retry y/n?&quot;);
          option = getch();
      } // end loop
  }
  </code></pre>
  <p>I only use scanf since we are still in scanf and printf.</p>
  <p>Please help me out, this is our first project in college.</p>