/* This program demonstrates * 1. Operator Precedence * 2. Implicit and explicit casting * 3. shortcut operators * 4. Increment and decrement */ #include using namespace std; int main() { /* Demonstrating operator precedence for the math operators * Precedence is the ORDER in whcih operators are executed */ int z,a,b,c,d,e,f; cout<<"Enter 6 integers: "; cin>>a>>b>>c>>d>>e>>f; z = a1- b * -c + d / (e-f); // Demonstrates operator precedence /* User entered 10 12 8 7 19 15 z = a - b * -c + d / (19 - 15) // parentheses has highest precedence z = a - b * -8 + d / 4 // unary minus z = a - 12 * -8 + d / 4 // * and / have same precedence, left associative, so * goes first z = a - -96 + 7 /4 // / goes after * z = 10 - -96 + 1 // - and + have the same precedence, left associative, so - goes first z = 106 + 1 // + has higher precedence than = z = 107 // assignment */ cout<<"The result is "<>i1>>i2>>d1>>d2; d3 = d1 * d2 - i1 / i2; /* i1 = 15, i2 = 6, d1 = 10, d2 = 5.62 * Multiply first: d1 - double, d2 - double, 10.0 * 5.62 = 56.2 * 56.2 - i1/i2 * Divide next: i1 - int, i2 - int 15/6 = 2 (integer math) * 56.2 - 2 * Subtract next: 56.2 - double, 2 - int: autoconverts int to double 56.2 -2.0 = 54.2 * d3 = 54.2 * assignment: d3 - double. 54.2 - double , just assign */ cout<<"Floating point result: "<(i1) / i2; // Pretend for the division only, that i1 is a double cout<<"d3 as int: "<(d3)<>money; cout<<"Enter income: "; cin>>income; money = money + income * 0.8; //update cout<<"Money is now : "<>val2; val1 = val1 + (12 * 0.37 - val2 / 19); cout<<"Long form operation: "<< val1 <