C# Basics Integers and Doubles Quiz Q7
Hi, hoping someone can help me understand the maths in this question, I've tried several times and it just isn't clicking for me.
int a = 3; int b = 2; double c = 3.5; double y = a / b * c;
y = ?
How I'm understanding it is:
First: b * c
2 * 3.5 = 7.0
Then: a / 7.0
3 / 7.0 = 0.4285714285714286
So: y = 0.4285714285714286
It's incorrect, so what am I doing wrong here..?
fatima Tavakoli12,074 Points
You have to consider the order of operations in math and also the type of variables (double and integer). Since we dont have parentheses and division and multiplication are in same order, we have to calculate them from left to right. First a\b = 3/2 = 1.5 but since a and b both of them are integer the result will be integer too => a/b = 1 And then 1 * 3.5 = 3.5.
Order of math operations:
- Multiplication and Division (from left to right).
- Addition and Subtraction (from left to right).