4.3 Save the Choice

Currently, the variable always hold the value 1. Let’s make it store the actual player choice.

When the input function asks the player to choose 1 (odds) or 2 (evens), it returns the selected number.

We can store the function return value in the variable. This way, the variable holds the value 1 or 2, according to the player’s choice.

🎓 Learn


What to Do

🙈 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");
--  GameInput.Number(1, 2);
++  int playerSide = GameInput.Number(1, 2);

🗒️ Program.cs - Final

GamePrint.Box("Welcome to the Odds and Evens Game!");

// Player chooses to play with odds or evens.
GamePrint.Input("Choose 1 for Odds or 2 for Evens");
int playerSide = GameInput.Number(1, 2);

(...)