DEV Community

Sabin Sim
Sabin Sim

Posted on

14. C# (Project B: The Gatekeeper)

Project B: The Gatekeeper

Practicing Boolean Logic & Nested Conditionals

This project is designed to strengthen your understanding of:

  • AND (&&)
  • OR (||)
  • Nested if statements
  • Logical control flow

It is not about authentication security.

It is about thinking in conditions.


Why This Project Exists

Many beginners understand individual conditions.

Few truly understand:

  • How multiple conditions combine
  • How execution stops early
  • How nested structures affect control flow

This project forces you to think in layers.

Like a real gatekeeper.


System Flow

Your program must follow this structured sequence.


1. Setup

At the top of your code, define the correct credentials:

  • ID → "admin"
  • Password → "1234"

Store them in variables.

Do not hard-code them inside conditions later.


2. First Gate — Login Check

Ask the user to input:

  • ID
  • Password

Now evaluate both using logical AND:

id == "admin" && pw == "1234"
Enter fullscreen mode Exit fullscreen mode

Both must be correct.

If either one is wrong:

  • Print "Intruder detected!"
  • Immediately terminate the program using return

Do not allow execution to continue.

This is your first layer of logic control.


3. Second Gate — Age Verification

If login succeeds, ask:

"Enter your age:"

Now introduce a nested condition.

Inside the successful login branch:

  • If age is less than 19
    → Print "Minors cannot access after 10 PM."

  • If age is 19 or older
    → Print "Access to admin page granted!"

This must be implemented as a nested if structure.

Not separate top-level if statements.


Required Concepts

You must use:

  • Boolean logic (&&, ||)
  • Comparison operators (==, <, >)
  • Nested if statements
  • Early termination using return

If you skip nested logic, you skip the entire point of this exercise.


Design Constraints

  1. Do not combine everything into one long condition.
  2. Do not remove the nested structure.
  3. Do not duplicate logic.
  4. Do not skip early termination on login failure.

The structure must reflect layered decision-making.


What This Project Is Really Teaching

You are practicing:

  • Sequential validation
  • Layered logic
  • Early exit strategy
  • Responsibility separation inside conditionals

This is how real systems validate input.

Not everything is checked at once.

Access is granted step by step.


Why I Am Not Posting the Solution

Because logic becomes yours only when:

  • You write it
  • You debug it
  • You step through it
  • You fix your own mistakes

Reading a solution builds recognition.

Writing it builds thinking.

Top comments (0)