New to C++ programming

I am new to C++ programming and I am going to submit the first exercise to school that I have to create a C++ program as follows:



Please input the formula:
1 + 2 * 3 =
/-------------------------\
| The answer is 7.00 |
\-------------------------/



The user is going enter the expression (i.e. 1 + 2 * 3 =) in one line and the program runs to give the answer. And I do not really know how to do...

1. How can I write the cin>> stuff that the compiler knows which are numbers and which are maths operators and calculate correctly with precedence rules? That means how can the computer know it is + - * or /, and calculate * and / first.
More important is, I have absolutely no idea how can I write the codes that follows to evaluate the expression.....

N.B. The user can enter 2/3/4 number expression, how can I do it to detect the number of numbers that the user has entered and start the mathematical evaluation?

2. The output box length should change accordingly with the length of the answer. How can I do it? that means:
/---------------------------\
| The answer is 10.00 |
\---------------------------/
OR
/---------------------------------\
| The answer is 100000.00 |
\---------------------------------/

3. On my instruction sheet, there is a hint saying "you may detect the number of operands by checking whether the input character is =" What does it mean and how can I achieve it?
ps. maximum number of number input of the the expression is 4 (3 maths operators in between and 1 more "=" after that)

Thank you for your generous help....
Last edited on
I am basing this program off of the understanding you know very little about the language:

declare all of your variables first off, if this is the largest equation you will get then you'll need 3 int's and 3 char's.

by simply typing cin >> int >> char >> int >> char >> int >> char the cin object reads in all of the correct information into the right variables.

I'll continue this further, but i have to go for now.
still cannot understand how can I write the program to do the mathematical calculation then....
Moreover, I am doubtful in how to detect the number of inputs (as the user can input 2/3/4 numbers freely.
anyone help me? plz....
What subject is this assignment based around? there are multiple ways to accomplish this program, but i need to know how this program should be build, Ex if you are learning arrays i would use arrays, functions etc...etc..
Last edited on
This is pretty complicated for a first C++ program, it would take me a decent chunk of time to do it myself, you'd have to tokenize and parse it.
google search infamous bajarne strousstrop desktop calculator
It is said to have
basic cin cout
conditional statement
loop

and the prof said array is not needed
Topic archived. No new replies allowed.