Cpp - Write program to check grade range with nested if statement

Requirements

Write program to check grade range with nested if statement

A is more than 90.

B is between 80 and 90.

C is between 70 and 80.

Less than 70 is failing.

Demo

#include <iostream>
  
int main()/*from  w w  w  .j  a  v a  2  s .c  o  m*/
{
    int grade;
    std::cout << "Enter a grade (1-100): ";
    std::cin >> grade;

    if (grade >= 70)
    {
        if (grade >= 90)
        {
            std::cout << "\nPass with an A grade\n";
            // return 0;
        }
        if (grade >= 80)
        {
            std::cout << "\nPass with a B grade\n";
            // return 0;
        }
        std::cout << "\nPass with a C grade\n";
    }
    else
        std::cout << "\nFail\n";
 
    return 0;
}

Result

Related Exercise