Ask Player Input

📖 Instructions#

Let’s now tackle the first step: Player chooses to play with odds or evens.

To complete it we need:

  1. A way to ask for player input.
  2. A way to save his choice.

Let’s start by solving step number one.


Programming languages don’t know what “odds” or “evens” means, so we use numbers to represent them: 1 for odds and 2 for evens.

To ask the player to make a choice, we need to do two things: print a message explaining what to type, and then read what they enter.

We already know how to print a message. To read input, we use a built-in function designed for that:

Console.ReadLine();

When the program reaches Console.ReadLine(), it pauses and waits for the player to type something and press Enter.

The program pauses at the input line until the player presses Enter.

✅ What to Do#

  • Print the message Choose 1 for Odds or 2 for Evens:.
  • Read the player’s input from the console.
  • Run the program.

🎯 Expected Outcome#

Welcome to Odds and Evens!
Choose 1 for Odds or 2 for Evens:
1

💡 Hints#

Hint 1

Find the comment that marks where this step belongs. That’s where your new lines go.

Hint 2

You need two lines: one to tell the player what to type, and one to wait for their response.

Hint 3

Use Console.WriteLine to print the message and Console.ReadLine to read the input.

🙈 Solution#

Tried, you must, before reveal the solution you may.

Program.csChanges

    // Player chooses to play with odds or evens.
++  Console.WriteLine("Choose 1 for Odds or 2 for Evens:");
++  Console.ReadLine();

Program.csFinal

Console.WriteLine("Welcome to Odds and Evens!");

// Player chooses to play with odds or evens.
Console.WriteLine("Choose 1 for Odds or 2 for Evens:");
Console.ReadLine();

(...)