Beginner BEDMAS Question

Hello! I have a question about how the order of operations works when doing simple math with C++. All of the forms and tutorials I have read say that C++ follows BEDMAS (brackets exponents division multiplication addition subtraction) but I ran into something that makes me question this.

The following is a test program I wrote to check the problem:

#include <iostream>

using namespace std;

int main()
{
int a,b;
a = 3/4*12+13;
b = 12*3/4+13;
cout<<"a="<<a<<"\n";
cout<<"b="<<b;
cin.get();
}

My calculator and the rules of BEDMAS tell me that both variables, a and b, should equal 22 but when I run this program, a=13 and b=22. If anyone knows why this is happening, I'd appreciate the explanation. Thanks!
its because you are using integers, 3/4 evaluates to zero as 4 does not go into 3 even once, with doubles it should work
what is happening is integer division. 3/4 = 0. use 3.0/4 to avoid this.
Topic archived. No new replies allowed.