Simple calculator in C++?

ok so i have to make a simple calculator in c++ ,the problem is that you can take only one input , like a line e.g "3+7" or "3/7" or "3-7", and the program has to automatically identify the operators and the operand and then do the operation respectively and give the output for e.g "3+7=10"...what functions do i have to use , or what identifiers and what will be the source code??. im fairly new to c++ so i dont know that much.
P.S I'm Programming in Visual C++ 2012.

What stuff have you learnt so far? I take it you are comfortable using std::string, cout, etc? And for loops and switch statements?

After reading the string, walk the string looking to see if the char is a digit (isdigit()), a space, or one of the operators. You should also treat other chars as an error.

If it's a number, you'll have to carry on until there is something other than a number. And when you spot the end of the run of numbers, you'll need to convert the substring to a number.

There is a pretty simple solution which just uses string concatenation plus the clear() method, but I'll leave you to work out the details.

Andy
Last edited on
i know about strings arrays integers , nested loops, while if for statements and all that .... i read stuff on the internet , should i use getline or scanf commands??
I would use a string + getline in C++ code. I see scanf as the C way to do the same thing.
Last edited on
Topic archived. No new replies allowed.