Determine if a Grade is Passing or Failing in C++

This exercise is designed to help you understand conditional statements in C++. You will create a simple program that takes a numeric grade input from the user and evaluates whether the grade is passing or failing based on a predefined threshold.

Typically, a grade of 60 or above is considered passing in many academic systems. This logic will be implemented using an `if-else` statement. The program will prompt the user to input a grade, check the value, and print a message indicating whether the grade is passing or failing.

By completing this exercise, you will practice input handling, conditional logic, and basic flow control — all essential parts of programming in C++.

Group

Flow Control in C++

Objective

1. Prompt the user to enter a numeric grade (e.g., 0–100).
2. Use an if-else statement to evaluate whether the grade is 60 or higher.
3. Print "Passing" if the grade is 60 or above; otherwise, print "Failing".
4. Test the program with various inputs to verify the logic.

Write a program that asks for a grade and determines whether it is passing or failing.

Example C++ Exercise

 Copy C++ Code
#include <iostream> // Include the iostream library for input and output

using namespace std; // Use the standard namespace

// Main function - starting point of the program
int main() {
    int grade; // Variable to store the grade input by the user

    // Ask the user to enter a grade
    cout << "Enter your grade (0-100): ";
    cin >> grade; // Read the user's input

    // Check if the grade is passing (60 or above)
    if (grade >= 60) {
        cout << "Passing" << endl; // Output if the grade is passing
    } else {
        cout << "Failing" << endl; // Output if the grade is failing
    }

    return 0; // Return 0 to indicate successful program execution
}

 Output

Enter your grade (0-100): 75
Passing

Share this C++ Exercise


More C++ Programming Exercises of Flow Control in C++

Explore our set of C++ Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C++. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C++.

  • Calculate the Factorial of a Number Using a Loop in C++

    This exercise teaches you how to calculate the factorial of a number using an iterative approach in C++. The factorial of a number N is the product of all positive integers less th...

  • Print Numbers from 1 to 100 Using a For Loop in C++

    In this exercise, you will learn how to use a `for` loop in C++ to print numbers from 1 to 100. A `for` loop is commonly used when you know the number of iterations in advance. In ...

  • Print a Triangle of Asterisks in C++

    In this exercise, you will write a C++ program that prints a triangle pattern using asterisks (`*`). This is a common exercise used to practice loops and nested loops. The pattern ...

  • Print Numbers from 10 to 1 in Reverse Order in C++

    In this exercise, you will write a C++ program that prints numbers from 10 to 1 in reverse order. This will help you practice using loops, particularly with decrementing values. By...

  • Simple Calculator Simulation in C++

    In this exercise, you will create a C++ program that simulates a basic calculator. The calculator will perform simple arithmetic operations such as addition, subtraction, multiplic...

  • Find the Largest of Three Numbers in C++

    In this exercise, you will write a C++ program that compares three numbers and determines which one is the largest. The program will use `if-else` statements to compare the three i...