title: Do While loop skipping user input in C++
body: <p>Having some difficulty figuring out the right syntax I should be using when trying to get the Do/While loop to work. I would like to write a calculator in C++ that allows the user to enter a string and then it does its thing and prints the result, asks the user if they want to go again or not.</p>
  
  <p>I have a simple main function so far just to get the Do/While loop right, but when I enter y or Y, the program just asks if I want to continue again, it doesnt give me the opporunity to run the "calculator" part again. What am I doing wrong?</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt; //cout, cin
  #include &lt;string&gt; //string
  #include &lt;algorithm&gt; //remove_if(), end(), begin(), erase()
  #include &lt;stack&gt; //stack&lt;type&gt;
  #include &lt;ctype.h&gt; //isdigit()
  #include &lt;vector&gt; //vectors
  #include &lt;stdlib.h&gt;
  
  using namespace std;
  
  int main()
  {
      string userInput = ""; //declaring and initialising a string called user input
      char ans;
  
      do {
  
          cout &lt;&lt; "Welcome to the calculator, please enter your calculation and then press enter when you are done." &lt;&lt; endl;
          cin &gt;&gt; userInput;
  
          userInput.erase(remove_if(userInput.begin(), userInput.end(), isspace), userInput.end()); //removes and then erases any spaces in the string
          userInput.erase(remove_if(userInput.begin(), userInput.end(), isalpha), userInput.end()); // removes and then erases any alphabetic charecters
                                                                                                    //this will leave only numbers and operators
          cout &lt;&lt; userInput &lt;&lt; endl;
          cout &lt;&lt; "Would you like to continue?" &lt;&lt; endl;
          cout &lt;&lt; "Please enter 'y' or 'n'" &lt;&lt; endl;
          cin &gt;&gt; ans;
  
      } while ((ans == 'y')||(ans == 'Y'));
  
      return 0;
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/BLiXb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BLiXb.png" alt="This is what I get in the Termninal"></a></p>