title: Problem with cin.get() in C++?
body: <p>I have the following code:</p>
  
  <pre><code>#include &lt;conio.h&gt;
  using namespace std;
  int _tmain(int argc, _TCHAR* argv[])
  {
          int x = 0;
          cout &lt;&lt; "Enter x: " ;
          cin &gt;&gt; x;
          if (cin.get() != '\n') // **line 1**
          {
              cin.ignore(1000,'\n');
              cout &lt;&lt; "Enter number: ";
              cin &gt;&gt; x;
          }
  
          double y = 0;
          cout &lt;&lt; "Enter y: ";
          cin &gt;&gt; y;       
          if (cin.get() != '\n'); // **Line 2**
          {
              cin.ignore(1000,'\n');
              cout &lt;&lt; "Enter y again: ";
              cin &gt;&gt; y;   
          }
          cout &lt;&lt; x &lt;&lt; ", " &lt;&lt; y;
  
      _getch();
  
      return 0;
  }
  </code></pre>
  
  <p>When executed, I can enter x value and it ignores <strong>Line 1</strong> as I expected. However, when the program asks for y value, I inputed a value but the program did not ignore the while at <strong>Line 2</strong>? I don't understand, what is the difference between <strong>Line 1</strong> and <strong>Line 2</strong>? And how can I make it work as expected?</p>