title: C++ Prompt User to continue or leave
body: <p>Actually i was just trying my hands upon C++ and stopped at this particular problem where instead of program getting closed, it should ask the user whether he/she wants to continue or wants to exit. Now for what i understand, i wrote the do-while code in ending lines but its not working. Please gimme a solution to it. Thanks!!  </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;stdio.h&gt;
  #include&lt;cstdlib&gt;
  #include&lt;string&gt;
  
  using namespace std;
  
  class Cal
  {
      public:
      int Add(int a, int b)
      {
          int res;
          res=(a+b);
          cout &lt;&lt; "Answer is " &lt;&lt; a &lt;&lt; "+" &lt;&lt; b &lt;&lt; "=" &lt;&lt; res &lt;&lt; endl;
      }
      int Sub(int a,int b)
      {
          int res;
          res=(a-b);
          cout &lt;&lt; "Answer is " &lt;&lt; a &lt;&lt; "-" &lt;&lt; b &lt;&lt; "=" &lt;&lt; res &lt;&lt; endl;
      }
      int Mul(int a,int b)
      {
          int res;
          res=(a*b);
          cout &lt;&lt; "Answer is " &lt;&lt; a &lt;&lt; "*" &lt;&lt; b &lt;&lt; "=" &lt;&lt; res &lt;&lt; endl;
      }
      int Div(int a,int b)
      {
          int res;
          res=(a/b);
          cout &lt;&lt; "Answer is " &lt;&lt; a &lt;&lt; "/" &lt;&lt; b &lt;&lt; "=" &lt;&lt; res &lt;&lt; endl;
      }
  };
  
  int main()
  {
      int first, second, res, operation;
  
      cout&lt;&lt;"**********************************"&lt;&lt;endl;
      cout&lt;&lt;"******* Simple Calculator ********"&lt;&lt;endl;
      cout&lt;&lt;"**********************************"&lt;&lt;endl;
      cout&lt;&lt;"Select the Operation: "&lt;&lt;endl;
      cout&lt;&lt;"1. Addition"&lt;&lt;endl;
      cout&lt;&lt;"2. Subtraction"&lt;&lt;endl;
      cout&lt;&lt;"3. Multiplication"&lt;&lt;endl;
      cout&lt;&lt;"4. Divison"&lt;&lt;endl;
      cout&lt;&lt;"Choosen Operation is: ";
      cin&gt;&gt;operation;
      cout &lt;&lt; "Enter the 1st Number: ";
      cin&gt;&gt;first;
      cout &lt;&lt; "Enter the 2nd Number: ";
      cin&gt;&gt;second;
  
      switch(operation){
      case 1:
          Cal a;
          a.Add(first,second);
          break;
      case 2:
          Cal b;
          b.Sub(first,second);
          break;
      case 3:
          Cal c;
          c.Mul(first,second);
          break;
      case 4:
          Cal d;
          d.Div(first,second);
          break;
      default:
          cout&lt;&lt; "Please Enter a Operation";
          break;
      }
  
      char ans;
      do
      {
         cout&lt;&lt; "Do you want to continue (Y/N)?\n";
         cout&lt;&lt; "You must type a 'Y' or an 'N' :";
         cin &gt;&gt; ans;
      }
      while((ans !='Y')&amp;&amp;(ans !='N')&amp;&amp;(ans !='y')&amp;&amp;(ans !='n'));
  }
  </code></pre>