Recognizing +, -, *, / from input (cin) ??

Hey everyone, my lecturer recently posed a very strange requirements for one of our codes. Basically its just a simple circle-drawing code which draws a circle based on the user's input (radius). However what he wants this time is that the input being able to read addition/subtractions/multiplication/division directly from the input.

Example: If a user enters the input "25+25" my code will return an error as its an incorrect input.

What my lecturer wants: If a user enters "25+25" as input, the program will read it as 50 and displays a circle of radius=50.

Is it even possible in C++ ? As far as I know, this isn't possible in C++, and the user must input twice if he wants to perform addition of inputs.

Hope someone is able to clear this up. Thanks in advance.
closed account (48bpfSEw)
You need an expression parser:
http://www.speqmath.com/tutorials/expression_parser_cpp/

But before you look at the solution try to find a solution of your own!

Ask yourself:

How would I identify a number in a string?
How could I identify an operator like "+"?
When is the expression finished?
and so on!
@Necip
Wow really didn't expect such a thing to be possible, this just goes to show my ignorance. Will definitely be working on this over the weekend. Thanks a lot !!
Last edited on
Topic archived. No new replies allowed.