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

Logical patterns (and, or, not) in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Logical patterns (and, not) in C#
📖 Scenario: You are building a simple security system that checks if a person can enter a building based on their ID badge and time of entry.
🎯 Goal: Create a program that uses logical patterns and and not to decide if entry is allowed.
📋 What You'll Learn
Create a boolean variable hasIDBadge with value true or false
Create an integer variable entryHour representing the hour of entry (0 to 23)
Create a boolean variable isWeekend to indicate if it is weekend
Use logical operators && (and) and ! (not) to check entry conditions
Print "Entry allowed" if conditions are met, otherwise print "Entry denied"
💡 Why This Matters
🌍 Real World
Security systems often check multiple conditions like ID badges and time to allow or deny access.
💼 Career
Understanding logical operators is essential for writing conditions in software development, especially in security, validation, and decision-making code.
Progress0 / 4 steps
1
Create initial variables
Create a boolean variable hasIDBadge and set it to true. Create an integer variable entryHour and set it to 14.
C Sharp (C#)
Need a hint?

Use bool for true/false and int for numbers.

2
Add weekend variable
Add a boolean variable isWeekend and set it to false.
C Sharp (C#)
Need a hint?

Weekend means no workday, so set isWeekend to false for now.

3
Write entry condition using logical operators
Write an if statement that checks if hasIDBadge is true and entryHour is between 9 and 17 inclusive and it is not weekend (isWeekend is false). Use && for and and ! for not.
C Sharp (C#)
Need a hint?

Use if (hasIDBadge && entryHour >= 9 && entryHour <= 17 && !isWeekend) to check all conditions.

4
Print the result
Inside the if block, write Console.WriteLine("Entry allowed"). Inside the else block, write Console.WriteLine("Entry denied").
C Sharp (C#)
Need a hint?

Use Console.WriteLine to show the message on screen.