title: Simple Calculator Help (C++)
body: <p>I wrote a very simple calculator program in C++ and it works fine! But can someone explain how I can modify this code such that it will be able to add more than 2 numbers at once?</p>
  
  <p>So instead of doing 2 + 2 for example, I want users to be able to do 2 + 2 + 2. But every time I try, it just adds the first two "2"s and gives 4, no matter how many + 2 you type after it.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  // input function
  void Input (float &amp;x, float &amp;y);
  
  float a=1.0, b=1.0, result;
  char operation;
  
  int main ()
  {
      cout &lt;&lt; "A simple calculator \n\n";
  
      cin &gt;&gt; a &gt;&gt; operation &gt;&gt; b;
  
      Input (a,b);
  
      cout &lt;&lt; result &lt;&lt; endl;
      system ("pause");
      return 0;
  }
  
  
  void Input (float &amp;x, float &amp;y)
  {
      a = x;
      b = y;
  
      switch (operation)
      {
      case '+':
          result = x + y;
      break;
  
      case '-':
          result = x - y;
      break;
  
      case '*':
          result = x * y;
      break;
  
      case '/':
          result = x / y;
      break;
  
      default:
          cout &lt;&lt; "Improper operation. Please input a correct calculation        operation: \n";
          cin &gt;&gt; a &gt;&gt; operation &gt;&gt; b;
          Input (a, b);
      }
  }
  </code></pre>
  
  <p>Thanks guys!</p>