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)
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.
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..