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

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

Re: Problem with Calculation 80 80

34 is the right answer two minus becomes plus

http://wiki.answers.com/Q/Do_a_minus_and_a_minus_make_a_plus

Re: Problem with Calculation 80 80

but if you use a normal calculator , the answer should be 30.

Does "normal" mean "broken" in this case? If that's what your calculator says, either it's broken, or you're not using it correctly.

Re: Problem with Calculation 80 80

a-(-b) = a + b

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.