Programming Concepts

Check your understanding - Assignments

What would be the result of the following assignments?

intScore = 3
intWeighting = 2
intBaseLine = 1
intCorrection = 4
intResult = intScore * intWeighting - intBaseline * intCorrection

Yes. The order of operations in computer languages follows the normal maths conventions, so multiplication is carried out before subtraction.
No. Multiplication comes first and then subtraction. Introducing brackets can change the order - bracketed operations take overall precedence - or make it clearer what is intended. Here we could write
intResult = (intScore * intWeighting) - (intBaseline * intCorrection)
The answer is the same, but it is easier to see the calculation that is intended.
No. Multiplication comes first and then subtraction. Introducing brackets can change the order - bracketed operations take overall precedence - or make it clearer what is intended. Here we could write
intResult = (intScore * intWeighting) - (intBaseline * intCorrection)
The answer is the same, but it is easier to see the calculation that is intended.
No. Multiplication comes first and then subtraction. Introducing brackets can change the order - bracketed operations take overall precedence - or make it clearer what is intended. Here we could write
intResult = (intScore * intWeighting) - (intBaseline * intCorrection)
The answer is the same, but it is easier to see the calculation that is intended.
No. No sequence of the given operators will give this answer.
← Previous 1 2 3 4 5 6 7 8 9 10 11 12 Next →