title: c++ task won't execute after while loop
body: <p>C++ newbie here. I'm not sure how to describe this but the task outside of the <code>while-loop</code> won't execute immediately. I need to enter the input value again to get it done.
  Here is my code:</p>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
  
      int fourDigitInt, firstDigit, secondDigit, thirdDigit, fourthDigit, i = 0;
  
      cout &lt;&lt; &quot;Enter a 4-digit integer  :  &quot;;
   
      cin &gt;&gt; fourDigitInt;
  
  
      while (fourDigitInt &gt; 9999 || !(cin &gt;&gt; fourDigitInt))
      {
  
          i++;
          if (i &gt;= 3)
          {
              cout &lt;&lt; &quot;You do not seem to understand the program instruction.\nPlease try again later.&quot; &lt;&lt; endl;
              return -1;
          }
          else
          {
  
              cout &lt;&lt; &quot;Error: Please make sure you are entering a 4-digit integer&quot; &lt;&lt; endl;
              cin.clear();
              cin.ignore(4, '\n');
              cout &lt;&lt; &quot;Enter a 4-digit integer  :  &quot;;
          }
      }
  
      firstDigit = fourDigitInt / 1000 % 10;
  
      secondDigit = fourDigitInt / 100 % 10;
  
      thirdDigit = fourDigitInt / 10 % 10;
  
      fourthDigit = fourDigitInt / 1 % 10;
  
      cout &lt;&lt; &quot;1st digit  :  &quot; &lt;&lt; firstDigit &lt;&lt; endl;
      cout &lt;&lt; &quot;2nd digit  :  &quot; &lt;&lt; secondDigit &lt;&lt; endl;
      cout &lt;&lt; &quot;3rd digit  :  &quot; &lt;&lt; thirdDigit &lt;&lt; endl;
      cout &lt;&lt; &quot;4th digit  :  &quot; &lt;&lt; fourthDigit &lt;&lt; endl;
  }
  </code></pre>
  <p>Here are some problems I encountered:</p>
  <p>1)If I enter a <code>string</code> first, it doesn't have any problem.
  2)But if I enter any number less than 9999, it won't execute the calculation unless I
  enter it again.
  3)If I enter a 5-digit number the <code>endl</code> won't work. It will just display <code>Enter a 4-digit integer  :  Error: Please make sure you are entering a 4-digit integer</code> which suppose to be a different line.</p>
  <p>Where exactly did I do wrong? Thank you in advance.</p>