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

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

Choose your learning style9 modes available
If-else execution flow
📖 Scenario: You are creating a simple program to check if a person is old enough to vote. Voting age is 18 years or older.
🎯 Goal: Build a program that uses if-else statements to decide if a person can vote based on their age.
📋 What You'll Learn
Create an integer variable called age with the value 20
Create an integer variable called votingAge with the value 18
Use an if-else statement to check if age is greater than or equal to votingAge
Print "You can vote!" if the condition is true
Print "You cannot vote yet." if the condition is false
💡 Why This Matters
🌍 Real World
Many applications need to make decisions based on user input or data, like checking age for voting or access permissions.
💼 Career
Understanding if-else statements is fundamental for programming jobs, as they control how programs respond to different situations.
Progress0 / 4 steps
1
Create the age variable
Create an integer variable called age and set it to 20.
C Sharp (C#)
Need a hint?

Use int to declare the variable and assign the value 20.

2
Create the votingAge variable
Create an integer variable called votingAge and set it to 18.
C Sharp (C#)
Need a hint?

Declare votingAge as an integer and assign 18.

3
Write the if-else statement
Write an if-else statement that checks if age is greater than or equal to votingAge. Use age >= votingAge as the condition.
C Sharp (C#)
Need a hint?

Use if (age >= votingAge) and else blocks with Console.WriteLine inside.

4
Print the result
Run the program and print the output to show if the person can vote or not.
C Sharp (C#)
Need a hint?

The program should print exactly You can vote! because age is 20.