title: String Calculator substr()
body: <p>I am creating a string calculator that is supposed to be left associative and have no operator precedence.  My main problem is that my algorithm in the switch statement is splitting my string into one sub-string and then making the rest of the string into another sub-string that is the rest of the expression. For example 10+3*6 should equal 78 but instead it is evaluating (3*6) first and then adding 10 giving the value of 28 which is incorrect.  Is there a way to fix this problem so that the string expression is evaluated from left to right?  Thanks in advance! </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;sstream&gt;
  #include&lt;string&gt;
  #include&lt;cctype&gt;
  #include&lt;cmath&gt;
  using namespace std; 
  
  enum {PLUS='+',MINUS='-',MULT='*'};
  
  int numberValue(string &amp;expr)
  {
    istringstream is(expr);
    int value = 0;
    is &gt;&gt; value;
    return value;
  }
  
  
  int expressionValue(string &amp;expr)
  {
      for(int i = 0;i&lt;expr.length();i++)
      {
          switch(expr.at(i))
          {
          case PLUS:
              return expressionValue(expr.substr(0,i)) + 
                  expressionValue(expr.substr(i+1,expr.length()-i-1));
          case MINUS:
  
              return  expressionValue(expr.substr(0,i)) -
                  expressionValue(expr.substr(i+1,expr.length()-i-1));
          case MULT:
  
              return  expressionValue(expr.substr(0,i)) *
                  expressionValue(expr.substr(i+1,expr.length()-i-1));
          }
      }
  
      return numberValue(expr);
  }
  
  int main()
  {
      string expressionString;
      cout &lt;&lt; "Enter An expression: " &lt;&lt; endl;
      cin &gt;&gt; expressionString;
      cout &lt;&lt; expressionValue(expressionString) &lt;&lt; endl;
      return 0;
  }
  </code></pre>