### Math Formulas using Variables

Hello All,

Working on a program that converts infix to postfix math formulas. Ive successfully converted the infix to a postfix notation but now i am having trouble solving the equation from the postfix form. Im trying to set a result equal to three variables as shown below:

result = op1 ch op2;

where op1 and op2 are numbers and ch is the operator (+-*/) depending on what the user entered into a string. The error im getting is that it expected a ";" before postfix so clearly it doesn't understand what im trying to do. Im looking for help on how to put the answer from op1 ch op2 into result. Thanks for all replies!
 `result = op1 ch op2;`

That is the equivalent of: `result = op1 '*' op2`.

You see, `'*'` is interpreted by the compiler as a character constant, not as an arithmetic operator.

What data types are, result, op1, and op2 declared with?
Irrelevant what datatypes, this code won't compile.

But it seems that you are trying to directly multiply the character constants of a string with another one, and put the result into 'result'.
If this is the case, then you should revise the topics arithmetic operations, and datatypes + character arrays(pointers) in C++.
Because the fact is that a `string` is just a pointer to a `char`, and is not recognised by the compiler as what seems to be their representations, in fact `strings` are just a series of
8bit numbers treated as 'characters' to gain readable output.

If the variables you declared, except `char ch;` are of an integral or floating point type,
Then you still would have to revise: arithmetic operations, and datatypes.
Because it just doesn't make sense to say: result = op1 42 op2, which is the equivalent of: result = op1 ch op2; (in the case that ch is of type `char`, which it's name indicates).

 Im trying to set a result equal to three variables as shown below:

ch in this case is not a variable.
This is one possible way of doing it:
 ``1234567891011`` ``````int op1=0,op2=0,result=0,code; cout<<"enter 1 for addition, 2 for subtraction...etc."; cin>>code; switch(code) { case 1: cout<<" addition result= "<
I'm trying to get it to calculate the cir, and the area, and the diameter, but I just do not know how to make the formula actually print and calculate, help.
Sorry I started last week
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051`` ``````#include "stdafx.h" #include #include #include using namespace std; double r; double pi = 3.14; double d = 2 * r; double cir = d * pi; bool is_negativer = r <= 0; string type; int _tmain(int argc, _TCHAR* argv[]) { cout << "This program will help you roughly determine the area, circumference, and diameter of a circle." <> r; while(is_negativer == false) { cout << "Invalid answer, it needs to be positive dummy" <> r; } cout << cir <> r; while(is_negativer == false) { cout << "Invalid answer, it needs to be positive dummy" <> r; } } return 0; }``````
Last edited on