Exercise 1 of 10 · Variables & Output
Coat Check Claim Ticket
What you will make
A small console program that prints a coat-check claim ticket with a claim number, an item description, and a rack number.
The one new idea: Declaring typed variables and printing their values with string interpolation
Almost every program starts by taking a few pieces of information and showing them back clearly — that's the foundation every later exercise builds on.
Go straight to the code ↓Most programs start the same way: take a few pieces of information, and show them back to the user in a readable form. In C#, you store a piece of information in a variable with a type (like int or string) and a name, and you show it with Console.WriteLine. The easiest way to mix a variable's value into a sentence is string interpolation: put a $ right before the opening quote of a string, and anything inside {curly braces} gets replaced with that expression's value.
Worked example
Here's a locker room key tag printed the same way:
int lockerNumber = 47;
string combo = "12-34-56";
bool isTopLocker = false;
Console.WriteLine("Locker Key Tag");
Console.WriteLine($"Locker: {lockerNumber}");
Console.WriteLine($"Combo: {combo}");
Console.WriteLine($"Top locker: {isTopLocker}");Locker Key Tag
Locker: 47
Combo: 12-34-56
Top locker: FalseNotice every line that needs to show a variable's value uses $"...", while the plain title line doesn't need it at all. Also notice a bool like isTopLocker prints as True or False (capitalized) when interpolated — that's just how C# formats booleans by default.
Your turn
The starter code prints a coat-check ticket: a claim number, an item description, and a rack number. One of the Console.WriteLine calls is missing the $ that turns a plain string into an interpolated one, so instead of showing the claim number, it prints the literal text {claimNumber} — curly braces and all. Find that line and add the missing $ so the real value shows up instead.
If something goes wrong
If you still see literal curly braces like {claimNumber} in the output after your fix, double check the $ is placed immediately before the opening " of that specific string — not somewhere else in the line. If you instead get a compiler error mentioning that a name doesn't exist, check that you spelled the variable name inside the braces exactly the way it was declared, since C# is case-sensitive and claimNumber and ClaimNumber are different names.
Write your code
Runs in your browser. Press Run (or Ctrl/Cmd+Enter) and the output is checked for you.
Press Esc then Tab to move keyboard focus out of the code editor.
Output will appear here after you run your code.The runtime is starting in the background. You can type now — it will be ready before you are.
The answer appears here once you have run your code at least once.
Things that often go wrong here
- Forgetting the $ prefix on a string that contains {curly braces}.
- Without $, C# treats the braces as literal text instead of a placeholder for the variable's value, so you see {claimNumber} printed as-is.
- Putting the $ in the wrong spot, such as after the opening quote.
- The $ has to sit immediately before the opening double quote of the string for the compiler to treat it as interpolated.
- Mixing string concatenation (+) and interpolation ($"...") in the same line without picking one consistently.
- Both work, but combining them carelessly causes confusing compiler errors.
Want a blank editor instead? Open the C# playground.