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

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

Choose your learning style9 modes available
Switch Statement Execution
📖 Scenario: Imagine you are building a simple program that tells the day type based on the day number. This is like a small calendar helper that says if a day is a weekday or weekend.
🎯 Goal: You will create a program that uses a switch statement to print whether a day number (1 to 7) is a weekday or weekend.
📋 What You'll Learn
Create an integer variable called dayNumber with a value from 1 to 7.
Use a switch statement on dayNumber.
Print "Weekday" for days 1 to 5.
Print "Weekend" for days 6 and 7.
Print "Invalid day" for any other number.
💡 Why This Matters
🌍 Real World
Switch statements help programs make decisions based on different values, like menus, commands, or day types.
💼 Career
Understanding switch statements is important for writing clear and efficient code in many software development jobs.
Progress0 / 4 steps
1
Create the day number variable
Create an integer variable called dayNumber and set it to 3.
C Sharp (C#)
Need a hint?

Use int dayNumber = 3; to create the variable.

2
Start the switch statement
Write a switch statement using dayNumber as the expression.
C Sharp (C#)
Need a hint?

Use switch (dayNumber) { } to start the switch.

3
Add cases for weekdays and weekends
Inside the switch, add cases for 1 to 5 that print "Weekday", cases for 6 and 7 that print "Weekend", and a default case that prints "Invalid day".
C Sharp (C#)
Need a hint?

Group cases 1 to 5 together to print "Weekday". Group 6 and 7 to print "Weekend". Use default for invalid days.

4
Run and display the output
Run the program and observe the output printed by the switch statement.
C Sharp (C#)
Need a hint?

The output should be Weekday because dayNumber is 3.