0

I want to program a scientific calculator, and in order to simplify the code and make multiple operations at one, I need to perform operations using a single text box string.

For example, the textbox has the text "5+5", when I press "=" the number "10" appears.

I was able to do that for the SUM operation:

var allNumbersAddedUp = numbersText.Split('+').Select(double.Parse).Sum();

What i was wondering now, is how to do the same thing for MULTIPLICATION, DIVISION, and SUBTRACTION.

Is there a way to convert the entire string to a number? let's say, if I insert "1+(2*3)" into the textbox, how can I get "7" to appear?

Thanks in advance!

silviussa
  • 1
  • 1
  • 7
  • You need a parser ,take look at this link http://stackoverflow.com/questions/7377344/how-do-i-write-a-parser-in-c – Arash Sep 23 '15 at 22:14

1 Answers1

0

Just Take one TextBox and One Button and Write Code in Cs File --> In Code Fileenter code here btnCalc.Attributes.Add("onclick", "document.getElementById('" + txtInput.ClientID + "').value = eval(document.getElementById('" + txtInput.ClientID + "').value); return false;");