### Evaluating arithmetic expressions using recursive descent parser

I have the following code to calculate arithmetic expressions :

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677`` ``````#include using namespace std; using namespace std; const char * expressionToParse = "6.5-2.5*10/5+2*5"; char peek() { return *expressionToParse; } char get() { return *expressionToParse++; } double expression(); double number() { double result = get() - '0'; while (peek() >= '0' && peek() <= '9') { result = 10*result + get() - '0'; } return result; } double factor() { if (peek() >= '0' && peek() <= '9') return number(); else if (peek() == '(') { get(); // '(' double result = expression(); get(); // ')' return result; } else if (peek() == '-') { get(); return -expression(); } return 0; // error } double term() { double result = factor(); while (peek() == '*' || peek() == '/') if (get() == '*') result *= factor(); else result /= factor(); return result; } double expression() { double result = term(); while (peek() == '+' || peek() == '-') if (get() == '+') result += term(); else result -= term(); return result; } int main(double argc, char* argv[]) { double result = expression(); cout << result << endl; return 0; }``````

The problem is that it does not work properly with decimal numbers
for example it evaluates 6-2*10/5+2*5 = 12 which is correct but for 6.5-2.5*10/5+2*5 it returns 6 instead of 11.5 .
 ``1234567891011121314151617181920212223242526272829303132`` ``````#include #include using namespace std; const char * expressionToParse = "6.5-2.5*10/5+2*5"; istringstream parse(expressionToParse) ; char peek() { return static_cast(parse.peek()) ; } char get() { return static_cast(parse.get()) ; } double expression(); double number() { double result ; parse >> result ; return result; } double factor() { if ((peek() >= '0' && peek() <= '9') || peek() == '.') return number(); // rest of the code doesn't require change... ``````