📖 Instructions#
Now we want to print the number the player chose. Unlike previous messages, this one needs to include the value of a variable — not just fixed text.
🧠 Recall
To combine text and a variable value in a single message, we use string interpolation:
int score = 10;
Console.WriteLine($"Your score is {score}.");The $ before the string marks it as interpolated. Any variable name inside {} is replaced with its value when the program runs.
🎓 Learn More
✅ What to Do#
Print the message You chose: followed by the value of playerNumber using string interpolation.
🎯 Expected Outcome#
Welcome to Odds and Evens!
Choose 1 for Odds or 2 for Evens:
1
You chose Odds.
Choose a number between 1 and 2:
1
You chose: 1
Welcome to Odds and Evens!
Choose 1 for Odds or 2 for Evens:
1
You chose Odds.
Choose a number between 1 and 2:
2
You chose: 2
💡 Hints#
Hint 1
You need a single print statement. The message contains both fixed text and a variable value.
Hint 2
String interpolation lets you embed a variable directly inside a string. Look at the code example in the instructions.
Hint 3
The string starts with $. Put the variable name inside {} where you want its value to appear.
⚠️ Common Mistakes#
Forgetting the $ prefix
Without the $, the curly braces are treated as plain text. The output will print You chose: {playerNumber} literally instead of the actual number.
Putting quotes inside the curly braces
Writing {"playerNumber"} instead of {playerNumber} prints the variable name as text rather than its value. The variable name inside {} needs no quotes.
Using + to combine text and variable
Writing "You chose: " + playerNumber works but is not the preferred approach when string interpolation is available. It also requires an explicit type conversion in some cases. Use the $ syntax instead.
🙈 Solution#
Tried, you must, before reveal the solution you may.
Program.csChanges
// Player enters a number between 1 and 2.
Console.WriteLine("Choose a number between 1 and 2:");
string rawNumber = Console.ReadLine();
int playerNumber = int.Parse(rawNumber);
+ Console.WriteLine($"You chose: {playerNumber}");
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 input = Console.ReadLine();
int playerChoice = int.Parse(input);
if (playerChoice == 1)
{
Console.WriteLine("You chose Odds.");
}
else
{
Console.WriteLine("You chose Evens.");
}
// Player enters a number between 1 and 2.
Console.WriteLine("Choose a number between 1 and 2:");
string rawNumber = Console.ReadLine();
int playerNumber = int.Parse(rawNumber);
Console.WriteLine($"You chose: {playerNumber}");
(...)