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!