5.2 Show the Number

Let’s print the selected number in the console.

Unlike the previous messages which were all text, this one will include the value of a variable.

To do it, we need to combine the variable value with the message string.

πŸŽ“ 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

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

# You chose: 1

πŸ–¨οΈ 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:
2

# You chose: 2

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

✏️ Program.cs - Changes

    // Player enters a number between 1 and 2.
    GamePrint.Input("Choose a number between 1 and 2");
    int playerNumber = GameInput.Number(1, 2);

++  GamePrint.Message("You chose: " + playerNumber);

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

(...)

// Player enters a number between 1 and 2.
GamePrint.Input("Choose a number between 1 and 2");
int playerNumber = GameInput.Number(1, 2);

GamePrint.Message("You chose: " + playerNumber);

(...)