4.5 Show the Correct Choice

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 ##

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

✏️ 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");
}

(...)