0
0
C Sharp (C#)programming~15 mins

If statement execution flow in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
If Statement Execution Flow
📖 Scenario: You are creating a simple program to check the temperature and give advice on what to wear. This helps you understand how decisions are made in a program using if statements.
🎯 Goal: Build a program that uses if statements to check the temperature and print the right clothing advice.
📋 What You'll Learn
Create an integer variable temperature with the value 15
Create an integer variable coldThreshold with the value 10
Use an if statement to check if temperature is less than coldThreshold
Print "Wear a coat" if the temperature is cold
Print "No coat needed" if the temperature is not cold
💡 Why This Matters
🌍 Real World
Checking weather conditions to give clothing advice is common in apps and websites.
💼 Career
Understanding if statements is essential for making decisions in any software development job.
Progress0 / 4 steps
1
Create the temperature variable
Create an integer variable called temperature and set it to 15.
C Sharp (C#)
Need a hint?

Use int temperature = 15; to create the variable.

2
Create the cold threshold variable
Create an integer variable called coldThreshold and set it to 10.
C Sharp (C#)
Need a hint?

Use int coldThreshold = 10; to create the variable.

3
Write the if statement to check temperature
Write an if statement that checks if temperature is less than coldThreshold. Inside the if, write Console.WriteLine("Wear a coat");. Use else to write Console.WriteLine("No coat needed"); when the temperature is not cold.
C Sharp (C#)
Need a hint?

Use if (temperature < coldThreshold) and else blocks with Console.WriteLine.

4
Print the result
Run the program and print the output to see the advice based on the temperature.
C Sharp (C#)
Need a hint?

The program should print "No coat needed" because 15 is not less than 10.