6.1 Calculate the Total

With both numbers defined, we can determine the round winner.

To determine it, we need to:

πŸ’» C#

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

Starting with the first step, we need to sum the player with the computer number.

We don’t have the actual numbers, but instead the variables where we stored them.

Making arithmetic operations with variables is the same as in math. But instead of numbers we use variables in their place.

πŸŽ“ Learn


And, like we did before when asking for numbers, to use the calculation result we need to store it in a variable: sum.


βœ… What to Do

🎯 Expected Outcome

πŸ–¨οΈ Console

+--------------------------------+
+-- Welcome to Odds and Evens! --+
+--------------------------------+


--> Choose 1 for Odds or 2 for Evens:
1

# You chose Odds
# Computer is Evens

--> Choose a number between 1 and 2:
1

# You chose: 1
# Computer chose: 2
# Sum is: 3

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

✏️ Program.cs - Changes

    // Add the two numbers.
++  int sum = playerNumber + computerNumber;
++  GamePrint.Message("Sum is: " + sum);

πŸ—’οΈ Program.cs - Final

(...)

// Add the two numbers.
int sum = playerNumber + computerNumber;
GamePrint.Message("Sum is: " + sum);

(...)