📖 Instructions#
Moving on to the second step, we need a way to save the player choice.
Right now, the program reads the player’s input but doesn’t do anything with it. We need a way to remember what the player typed so the game can use it later.
To do that, we use a variable .
A variable is like a labeled box: you give it a name, and you put a value inside. Later, you can open the box to read or change what’s in it.
int score = 0;This creates a variable named score that holds the value 0. Wherever you write score in the program, it refers to that stored value.
Some functions do more than just run — they also return a value when they finish. You can capture that value by assigning it to a variable, just like above:
string result = Console.ReadLine();Here, the function reads what the user typed and hands it back. That value is then stored in the variable result.
🎓 Learn More
✅ What to Do#
- Update the line that reads the player’s input so that the result is stored in a variable named
playerChoice. - Run the program.
🎯 Expected Outcome#
The program should behave exactly as before — no visible change in the console output. The difference is that the player’s input is now saved and ready to be used.
Welcome to Odds and Evens!
Choose 1 for Odds or 2 for Evens:
1Not all progress is visible. Storing a value in a variable doesn’t produce output, but it is an essential step for what comes next.
💡 Hints#
Hint 1
Find the line with Console.ReadLine(). That’s the one you need to update.
Hint 2
You need to declare a variable and assign the result of Console.ReadLine() to it in the same line.
Hint 3
The player’s choice is text, so the variable type should be string.
🙈 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();
++ string playerChoice = 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:");
string playerChoice = Console.ReadLine();
(...)