📖 Instructions#
The game currently plays a single round and stops. To play multiple rounds we need to repeat the round code until one player wins twice.
Before we do that, we need to clearly identify which code belongs to a single round. Looking at the program, everything from asking the player for a number to announcing the round winner makes up one round.
Adding a comment before and after that block makes the boundary visible — both to you as the author and to anyone reading the code later.
✅ What to Do#
Add a comment // Round starts here. before the round code and // Round ends here. after it.
🎯 Expected Outcome#
No change in program behaviour. The output is identical to the previous lesson. The only difference is two new comment lines in the code.
💡 Hints#
Hint 1
The round starts where the player is asked to choose a number.
Hint 2
The round ends after the winner of that round is announced.
⚠️ Common Mistakes#
Placing the comments in the wrong position
The // Round starts here. comment belongs before Console.WriteLine("Choose a number between 1 and 2:");. The // Round ends here. comment belongs after the closing } of the if/else block that prints the round winner.
Including the player choice and setup code inside the round
The player’s choice of odds or evens happens once at the start of the game — it is not part of the round. The round only covers picking numbers, calculating the sum, and deciding the winner.
🙈 Solution#
Tried, you must, before reveal the solution you may.
Program.csChanges
+ // Round starts here.
// 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}");
// Computer randomly generates a number between 1 and 2.
Random random = new Random();
int computerNumber = random.Next(1, 3);
Console.WriteLine($"Computer chose: {computerNumber}");
// Add the two numbers.
int sum = playerNumber + computerNumber;
Console.WriteLine($"Sum is: {sum}");
// Check if the sum is odd or even.
bool sumIsEven = sum % 2 == 0;
// Decide the round winner.
bool playerIsEven = playerChoice == 2;
if (playerIsEven == sumIsEven)
{
Console.WriteLine("You win this round!");
}
else
{
Console.WriteLine("Computer wins this round!");
}
+ // Round ends here.
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.");
}
// Round starts here.
// 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}");
// Computer randomly generates a number between 1 and 2.
Random random = new Random();
int computerNumber = random.Next(1, 3);
Console.WriteLine($"Computer chose: {computerNumber}");
// Add the two numbers.
int sum = playerNumber + computerNumber;
Console.WriteLine($"Sum is: {sum}");
// Check if the sum is odd or even.
bool sumIsEven = sum % 2 == 0;
// Decide the round winner.
bool playerIsEven = playerChoice == 2;
if (playerIsEven == sumIsEven)
{
Console.WriteLine("You win this round!");
}
else
{
Console.WriteLine("Computer wins this round!");
}
// Round ends here.
(...)