Problem with Calculation

Hey guys , i have a small problem regarding calculation in c++. Here is an example below


1
2
3
4
5
6
7
8
9
int main() 
{
  int f = -32;
  int d = 2;

   int re = d - f;
   int re2 = 2 - (-32);
   int re3 = 2 - - 32
}


The problem i am having is that all 3 results show the answer is 34 , but if you use a normal calculator , the answer should be 30.

How can i solve this problem within c++? Hope for some input here. Thanks
Yes the right answer is 34. What do you mean with 'normal calculator'. Why would such a thing calculate the wrong answer?
Last edited on
When you say "normal calculator", I'm guessing you mean non scientific, one operation entered at a time kind of thing. If so, then differences in results are most likely due to discrepancies in order of precedence of operators. Thus it is if anything the fault of the "normal calculator".

See BODMAS: http://www.mathsisfun.com/operation-order-bodmas.html ;)

You can use brackets to manipulate the order of precedence to what you want.
Last edited on
Topic archived. No new replies allowed.