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
βοΈ 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);
(...)