The program is now printing both possible outcomes.
Letβs change it to display only the correct message depending on the playerβs choice.
We need to run only one of the statements, either the player chose odds and computer gets evens, or the other way around.
We can use an if-else statement to select which statements to run.
π Learn
In this specific case, it should be something like:
π€ Pseudocode
if player side equals 1
player chose odds and computer gets evens
else
player chose evens and computer gets odds
To create the if-else condition, we need to
compare
the player side with the number 1.
π Learn
β 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 ##
π¨οΈ Console
+--------------------------------+
+-- Welcome to Odds and Evens! --+
+--------------------------------+
--> Choose 1 for Odds or 2 for Evens:
2
## You chose Evens, Computer is Odds ##
βοΈ Program.cs - Changes
// Player chooses to play with odds or evens.
GamePrint.Input("Choose 1 for Odds or 2 for Evens");
int playerSide = GameInput.Number(1, 2);
++ if (playerSide == 1)
++ {
GamePrint.Message("You chose Odds, Computer is Evens");
++ }
++ else
++ {
GamePrint.Message("You chose Evens, Computer is Odds");
++ }ποΈ Program.cs - Final
(...)
// Player chooses to play with odds or evens.
GamePrint.Input("Choose 1 for Odds or 2 for Evens");
int playerSide = GameInput.Number(1, 2);
if (playerSide == 1)
{
GamePrint.Message("You chose Odds, Computer is Evens");
}
else
{
GamePrint.Message("You chose Evens, Computer is Odds");
}
(...)