Context#
Your game plan says the player chooses odds or evens at the start — and that choice decides who wins each round. Look at the two comments in your code:
// Player chooses to play with odds or evens.
// ...
// Decide the round winner.The winner decision depends on knowing what the player chose. But right now the program reads the player’s input and immediately forgets it. By the time the game needs it, it’s gone.
Activity 1 — What changes?#
Build this activity in Moodle as H5P Fill in the Blanks.
The program asks the player to type their choice. Look at these two runs of the program and complete what the output should say.
Run A — the player types Odds
You chose ___
Run B — the player types Evens
You chose ___
H5P configuration#
Type: Fill in the Blanks
Text:
Run A — the player types [Odds]:
You chose *Odds*.
Run B — the player types [Evens]:
You chose *Evens*.Feedback — correct:
Exactly. The output depends entirely on what the player typed. If the program is going to say “You chose Odds” or “You chose Evens”, it needs to know which one the player chose — and it needs to know it at the right moment.
Feedback — incorrect:
Look at what the player typed in each run. The output should reflect exactly that — the program is reporting the player’s own choice back to them.
Activity 2 — What does the program need?#
Build this activity in Moodle as H5P Drag the Words.
The output depends on what the player typed. But right now the program doesn’t hold onto that value long enough to use it.
Complete the sentence:
The program needs to ___ the player’s choice the moment they type it, so it can ___ it later when the game needs it.
H5P configuration#
Type: Drag the Words
Text:
The program needs to *remember* the player's choice the moment they
type it, so it can *use* it later when the game needs it.Distractors: forget find delete
Feedback — both correct:
Exactly. The program needs to remember the value the moment it arrives, so it can use it later. In programming, the way a program remembers a value is by saving it in a variable.
A variable has a name — so the program can find it again — and it holds the value for as long as the program needs it.
Here is what that looks like in your code:
string input = Console.ReadLine();
inputis the variable. The moment the player presses Enter, their choice is saved ininputand stays there. Any part of the program that needs to know what the player typed can useinputto find out.
Feedback — gap 1 wrong (chose forget):
Look at the context again. The program currently forgets the value — that is the problem we are solving, not the solution. What does the program need to do at the moment the player types their choice?
Feedback — gap 2 wrong (chose find):
The program cannot go looking for a value it never kept hold of. It needs to have saved it first. Once it is saved, the program can use it — but finding it later only works if something remembered it earlier.
Feedback — gap 2 wrong (chose delete):
If the program deletes the value, it is gone immediately — the same problem as before. The program needs to hold onto it, not remove it.
Implementation#
Add this line to your program, replacing the existing Console.ReadLine()
line in the choose odds or evens step:
Console.WriteLine("Welcome to Odds and Evens!");
Console.WriteLine("Choose Odds or Evens:");
- Console.ReadLine();
+ string input = Console.ReadLine();
Run and Observe#
Run the program. Type Odds and press Enter.
The program doesn’t show the choice yet — that comes in the next step. But
the value is no longer lost. It is saved in input, ready to be used.
Welcome to Odds and Evens!
Choose Odds or Evens:
Odds
What’s Next#
In the next step you will use input to show the player what they chose.
That is when the variable does its job for the first time.
Stuck on what a variable is or how it works? Go to the Variable concept module