I would like to build a basic calculator using C#.
However, I aim to build one which performs calculation only after the equal button is clicked. And I think that arrays need to be used.
For example, when someone type in "10+12/2-2", the calculator will display "10+12/2-2 = 10" after the "=" button is clicked.
Any idea how to do it?
Thank you very much for your help.
Guest UserPosted Aug 7, 2014, 9:29 PM
You need expression parser, where you enter such formula and get the output.
Now two ways to do that:
# Reinvent the wheel: this approach you've to write your own code to split the "10+12/2-2" into operator & operand then BODMASS ... get the output as "10". Fairly time consuming
# the other option is to use any package and pass "10+12/2-2" as input and you'll get output as "10". Easy, simple, I hope you like this better.
Use any expression evaluator based on ANTLR , e.g.., download below
http://csharpeval.codeplex.com/
http://www.codeproject.com/Articles/241830/a-Tiny-Expression-Evaluator