Determine if a Grade is Passing or Failing (If-Else Logic) in C++
Master conditional statements and input handling by creating a program that evaluates academic performance based on a specific threshold.
Decision Making Logic
Relational Operators
Using the >= operator allows the program to compare the user's input against the threshold of 60 to return a boolean result.
If-Else Branching
This structure directs the program flow into two distinct paths: one for success (True) and another for failure (False).
Key Concepts Learned:
- Conditional Logic: Using
if-elseto control program execution. - Input Streams: Capturing numeric data from the user with
cin. - Flow Control: Understanding how programs make decisions at runtime.
Course:
Control Flow & Logic
Step-by-Step Objective
- Prompt the user to enter a numeric grade (0–100).
- Store the input value in an
intvariable. - Evaluate if the value is 60 or higher using an
ifstatement. - Display "Passing" for successful results and "Failing" otherwise.
C++ Solution
grade_checker.cpp
Flow Control
#include <iostream>
using namespace std;
int main() {
int grade;
cout << "Enter your grade (0-100): ";
cin >> grade;
// Check the condition
if (grade >= 60) {
cout << "Passing" << endl;
} else {
cout << "Failing" << endl;
}
return 0;
}
Console Output:
Enter your grade (0-100): 75
Passing
Flow Control & Relational Logic