I have been trying to build a calculator, and i got to a point where i have 2 arrays: char array that contains the math operation signs and a int array for the numbers. And I need to do the calculation.
for example, the 2 arrays are:
so it is supposed to get this:Code:int Nums[]={12, 8, 7, 3}; char Signs[]={+, /, (, -, );
12+8/(7-3)
which is 5.
the terms are:
- the program should know what comes after what.(because there is only 1 possible option at a time).
- there are only 6 signs: +, -, /, *, (, ).
- If the user doesnt provide brackets around divide or multiple operation (or any other operation) the program should calculate from left to right, and not in order of arithmetic operations.
- The user should be able to insert brackets into other ones, or in the begining.
I have already wrote the code for the 4 arithmetic operations, but when the brackets came in i got lost. I think i can think of something to suite them, but it's really long and inefficient code.
Can someone give me an idea how to do this?
Thanks in advance.



LinkBack URL
About LinkBacks



