Simple Calculator Expression Solver

Hi I'm trying to create a simple calculator which can read continuous inputs for eg. it can do this
x+y or x+y+z or 5+3-6+9/2 or a+b+c+d+e..... and so on. I hope you're getting what I want to do. I'll write the expression and want it to be solved according to the math logic too as we know in general. 5+5*3 = 30 will be 30 in c++ but I want it to be 5+(5*3)=20. I tried some codes but I wasn't even 1% close to the desired code so please tell me how to do it.
Note: If this question had been asked and solved already then forgive me and redirect me to that post.
Last edited on
You apparently want to do symbolic math.

Note that x+y+z is not an equation. It is an expression with named variables.

5+5*3 is an expression as well, but with known values. You have to parse the string correctly. You probably did read and evaluate tokens one by one, but you should parse the whole expression first, before evaluation. Yes, this "simple" exercise is common.

Named variables add extra challenge.

C++ can be used, but check first something like: http://sympy.org/en/index.html
Thanks your your reply but I was hoping for a source code in c++ to understand how to do it. can you post a source code of the calculator program I want?

Topic archived. No new replies allowed.