title: C++ Loop logic / cin.ignore() stalling loop
body: <p>I'm trying to figure out the logic for a user who has to enter a three digit integer (x). This integer or integers go into a another container class hence the need for place.insert(x);. If user enters -1 then the method should stop taking in input. For some reason if I do not put a delimiter or anything inside of cin.ignore() it just stalls the program. If I put cin.ignore(10000,'\n') it will clear it but when I enter in a new number ie &quot;222&quot;, in the debugger it shows &quot;22&quot; instead. (Would like to know why that is also!) For the while condition I use (x != -1 &amp;&amp; x &lt; 100 || x &gt; 999) but is that redundant because x can be -1...? I do not want to use break and would like to know if there is a way to make this work or even a better logic that I should be implying. I'm trying to have it be able to validate if user enters &quot;dlsfjd&quot; or even just &quot;z&quot; and or anything higher or lower than 3 digits.</p>
  <pre><code>    int x;
  
      do {
          cin &gt;&gt; x;
  
          if (cin.fail() || x &lt; 100 || x &gt; 999) {
              cout &lt;&lt; &quot;Input failed. Please try again: &quot;;
              cin.clear();
              cin.ignore();
          } else
              place.insert(x);
  
      } while(X != -1 &amp;&amp; X &lt; 100 || X &gt; 999);
  </code></pre>