6.2 Determine Odd or Even

Now, we can proceed to the next step:

๐Ÿ’ป C#

// Add the two numbers.
// --> Check if the sum is odd or even.
// Decide the round winner.

A common way to do it is by using the modulo operator.

๐ŸŽ“ Learn


We need to calculate the modulo of the sum by 2 and compare it with 0.

The result of any comparison is no longer a number, but instead a boolean value. A comparison result is either true or false.

If the modulo is 0, it returns true meaning the number is even, otherwise it returns false meaning its odd.


โœ… What to Do


๐Ÿ™ˆ Solution
Tried, you must, before reveal the solution you may. - Yoda

โœ๏ธ Program.cs - Changes

    // Check if the sum is odd or even.
++  bool sumIsEvens = sum % 2 == 0;

๐Ÿ—’๏ธ Program.cs - Final

(...)

// Check if the sum is odd or even.
bool sumIsEvens = sum % 2 == 0;

(...)