Learn to store information in variables and create interactive programs that talk to users! (Ages 8-18)
VariablesAndInput/
├── .git/
├── .gitignore
├── VariablesAndInput.csproj
└── Program.cs
- What to do: Go to https://github.com/PhillyCoderDojo/session2-variables → Click "Fork" → Open GitHub Desktop → Clone your fork to your computer
- Where we're working: Making your own copy of today's starter project
- Code snippet: None
- Why it matters: You get your own playground to experiment in
- Git command:
git clone https://github.com/YOUR-USERNAME/session2-variables.git - 📸 SCREENSHOT: Fork button in top right, then GitHub Desktop clone dialog
- What to do: Open Rider → File → Open → Navigate to your cloned folder → Select it → Click OK
- Where we're working: Loading your project into the coding tool
- Code snippet: None
- Why it matters: Time to start coding!
- Git command: None
- 📸 SCREENSHOT: Rider with project loaded in Solution Explorer
- What to do: Open Program.cs and type these lines
- Where we're working: Program.cs file
- Code snippet:
string myName = "Alex";
Console.WriteLine("Hello, " + myName);- Why it matters: Variables are like boxes that hold information
- Git command:
git add . && git commit -m "Add first string variable" - 📸 SCREENSHOT: Code editor showing the variable declaration
- What to do: Add these lines below your name code
- Where we're working: Program.cs file
- Code snippet:
int myAge = 12;
double myHeight = 5.5;
Console.WriteLine($"I am {myAge} years old and {myHeight} feet tall");- Why it matters: Different boxes (variables) hold different types of things
- Git command:
git add . && git commit -m "Add integer and double variables" - 📸 SCREENSHOT: Code showing all three variable types
- What to do: Replace your code with this interactive version
- Where we're working: Program.cs file
- Code snippet:
Console.Write("What is your name? ");
string userName = Console.ReadLine();
Console.WriteLine($"Nice to meet you, {userName}!");- Why it matters: Programs become fun when they respond to users
- Git command:
git add . && git commit -m "Add user input for name" - 📸 SCREENSHOT: Console showing the prompt and user typing
- What to do: Add this code to ask for the user's age
- Where we're working: Program.cs file (add after name code)
- Code snippet:
Console.Write("How old are you? ");
string ageText = Console.ReadLine();
int userAge = int.Parse(ageText);
Console.WriteLine($"Wow! In 10 years you'll be {userAge + 10}!");- Why it matters: Converting text to numbers lets us do math
- Git command:
git add . && git commit -m "Add age input with calculation" - 📸 SCREENSHOT: Console showing age calculation result
- What to do: Create a complete profile program
- Where we're working: Replace all code in Program.cs
- Code snippet:
Console.WriteLine("=== Profile Builder ===");
Console.Write("Enter your name: ");
string name = Console.ReadLine();
Console.Write("Enter your age: ");
int age = int.Parse(Console.ReadLine());
Console.Write("Enter your favorite color: ");
string color = Console.ReadLine();
Console.Write("Do you like pizza? (yes/no): ");
bool likesPizza = Console.ReadLine().ToLower() == "yes";
Console.WriteLine("\n=== Your Profile ===");
Console.WriteLine($"Name: {name}");
Console.WriteLine($"Age: {age}");
Console.WriteLine($"Favorite Color: {color}");
Console.WriteLine($"Likes Pizza: {likesPizza}");- Why it matters: Combining everything into a real program
- Git command:
git add . && git commit -m "Create complete profile questionnaire" - 📸 SCREENSHOT: Full program output with user responses
- What to do: In GitHub Desktop → Click "Push origin" to upload your branch
- Where we're working: Sending your code to GitHub
- Code snippet: None
- Why it matters: Backs up your work and prepares for sharing
- Git command:
git push origin my-variables - 📸 SCREENSHOT: GitHub Desktop showing successful push
- Press Ctrl+F5 or click the green
▶️ button - Answer all the questions when prompted
- Common Error: "Input string was not in a correct format" - happens when typing letters for age
- Fix: Make sure to type only numbers when asked for age
Create a Personal Calculator that asks for two numbers and shows all math operations!
Hint:
Console.Write("First number: ");
double num1 = double.Parse(Console.ReadLine());
Console.Write("Second number: ");
double num2 = double.Parse(Console.ReadLine());
Console.WriteLine($"{num1} + {num2} = {num1 + num2}");
// Add subtraction, multiplication, division!Super Stretch: Use int.TryParse() to handle bad input:
if (int.TryParse(Console.ReadLine(), out int result))
{
Console.WriteLine($"You entered: {result}");
}
else
{
Console.WriteLine("That's not a number!");
}