4. Pass or Fail Checker

Easy ⏱️ 5 min

Problem Statement

Given a student's mark as input, print output as Pass/Fail based on the input
mark < 35 print Fail
mark>=35 print Pass

Input Format:
Accept an integer as input
Output Format:
Print the output as "Pass" or "Fail"
Constraints:
0 <= INPUT <= 10^9
Sample Input 1:
34
Sample Output 1:
FAIL
Sample Input 2:
35
Sample Output 2:
PASS
🧱 C++ Comparison Operators Guide
📊 The Less Than Operator (<)

The < operator checks if the left value is strictly less than the right value.

Syntax: value1 < value2

Returns: true if value1 is less than value2, otherwise false

Examples:

  • 34 < 35 → TRUE (34 is less than 35)
  • 35 < 35 → FALSE (35 is NOT less than 35, they're equal)
  • 36 < 35 → FALSE (36 is greater than 35)
  • 0 < 35 → TRUE (0 is less than 35)

Key point: The value must be strictly smaller, not equal!

⚖️ All Comparison Operators

C++ provides six comparison operators:

  • == → Equal to (checks if two values are the same)
  • != → Not equal to
  • < → Less than
  • > → Greater than
  • <= → Less than or equal to
  • >= → Greater than or equal to

For our problem:

We could also write it as: if (marks >= 35) cout << "PASS"; else cout << "FAIL";

Both approaches are correct! The choice depends on which logic feels more natural.

🎯 Understanding the Pass/Fail Logic

The rule:

  • Marks < 35 → Student FAILS
  • Marks >= 35 → Student PASSES

Breaking it down:

if (marks < 35) → Check if marks are below passing threshold

  • If TRUE (marks are less than 35) → Print "FAIL"
  • If FALSE (marks are 35 or more) → Print "PASS"

Boundary case:

Marks = 35 is PASS (exactly at the threshold)

Marks = 34 is FAIL (just below the threshold)

🔍 Step-by-Step Execution

Example 1: marks = 34

  1. Read input: marks = 34
  2. Check condition: if (34 < 35)
  3. Evaluate: 34 < 35 is TRUE
  4. Execute if block: cout << "FAIL";
  5. Output: FAIL

Example 2: marks = 35

  1. Read input: marks = 35
  2. Check condition: if (35 < 35)
  3. Evaluate: 35 < 35 is FALSE (equal, not less than)
  4. Skip if block, execute else: cout << "PASS";
  5. Output: PASS

Example 3: marks = 90

  1. Read input: marks = 90
  2. Check condition: if (90 < 35)
  3. Evaluate: 90 < 35 is FALSE
  4. Skip if block, execute else: cout << "PASS";
  5. Output: PASS
💡 Data Type Choice: int vs long long

In this problem, we use int instead of long long. Why?

Constraint analysis:

0 <= INPUT <= 10^9

Data type ranges:

  • int → -2×10^9 to 2×10^9 (approximately)
  • long long → -9×10^18 to 9×10^18

✅ Since 10^9 fits comfortably within int range, we use int for efficiency.

🔄 If the constraint was 10^15, we'd need long long.

💡 Pro tip: Always choose the smallest data type that can handle your constraints to save memory!

💡 Tip: When comparing values, make sure you understand the boundary conditions (like exactly 35 in this case)!

Solution

#include <iostream>

using namespace std;

int main() {
    int marks;
    cin >> marks;
    
    if (marks < 35)
        cout << "FAIL";
    else
        cout << "PASS";
    
    return 0;
}