title: How Can I avoid char input for an int variable?
body: <p>The program below shows a 'int' value being entered and being output at the same time. However, when I entered a character, it goes into an infinite loop displaying the previous 'int' value entered. How can I avoid a character being entered?</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  int main(){
  int n;
  
  while(n!=0){
              cin&gt;&gt;n;
              cout&lt;&lt;n&lt;&lt;endl;
             }
  return 0;
  }
  </code></pre>