Click here to Skip to main content
12,951,732 members (69,834 online)
Rate this:
 
Please Sign up or sign in to vote.
I need a code which can solve the equations like this :-
56*78+(78/8)

In this we know that brackets must be solved first and then divide/multiply and then add/subtract.
So, i need a code for solving this kind of equations which contains multiple operators in single line.

Thnks :)
Posted 17-Jul-12 2:24am
Updated 17-Jul-12 2:37am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I think this is what you are looking for

Expression Evaluator for C# based on Expression Tree[^]

Just do the following using sample code in the above article:

IParser par = new ExpParser();
ExpEvaluator eu = new ExpEvaluator(par); 
string expresion = "56*78+(78/8)"
eu.SetExpression(expresion);
double res =eu.Evaluate();
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You should use google to search for "mathematical expression parser". There are thousands of results. Here are some promising ones:
Mathematical Expression Parser Using Recursive Descent Parsing[^]
a Tiny Parser Generator v1.2[^]
Simple(x) Numerical Formula Parser[^]
Expression Evaluator for C# based on Expression Tree[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,229
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 17 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100