title: cin.get() not functioning as desired
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/12272277/program-not-waiting-for-cin">Program not waiting for cin</a>  </p>
  </blockquote>
  
  
  
  <p>I wrote the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  void search(int pre, int a, int b, int x) {
      char c;
      cout &lt;&lt; "Is the number " &lt;&lt; ((x == 2) ? b : a) &lt;&lt; endl;
      c = cin.get(); ////// this does not block
      if (c == 'y') return;
  
      else {
          cout &lt;&lt; "Is the number " &lt;&lt; ((x == 2) ? b : a) &lt;&lt; " closer to your number than " &lt;&lt; pre;
          c = cin.get();
  
          if (c == 'y') {
              search(a, a, (a + b) / 2, 2);
          } //c=='y'
          else search(a, (a + b) / 2, b, 1);
      }
  }
  
  int main() {
      int N;
      cout &lt;&lt; "Enter N? ";
      cin &gt;&gt; N;
  
      search(N, 1, N, 1);
      return 0;
  }
  </code></pre>
  
  <p>No need to worry if you don't understand the logic because my question is not regarding that.</p>
  
  <p>In the search function, there are two cin.get(), where i need the user to enter a character. My problem is that the the program blocks for input only after the second cin.get(). </p>
  
  <p>For example:</p>
  
  <pre><code> Is the number 7  //program doesn't wait after this
   Is the number 7 closer to your number than 8  //program blocks here for an input
  </code></pre>
  
  <p>Why does it do so?</p>