3

I am writing a program in c++ that shows if an expression (example 98+56*(4+7) < 7-6*6) is true or false.. The expression will be taken as an input from the user..

Is there any function that I can use for this?

Vincent Savard
  • 32,695
  • 10
  • 65
  • 72
Adela
  • 35
  • 8

2 Answers2

4

You need math expression evaluator.

You can try this library: https://fastmathparser.codeplex.com/

In the link you'll find a sample code.

You can find an algo in this link: Evaluating arithmetic expressions from string in C++

Community
  • 1
  • 1
p.magalhaes
  • 6,610
  • 9
  • 48
  • 97
1

No, but implementing the Shunting Yard Algorithm is fairly easy if you are reasonably competent at programming.

I know link only answers are abhorred but here is the link on wikipedia (which is unlikely to disappear soon) and is actually quite good.

graham.reeds
  • 15,795
  • 16
  • 68
  • 133