Saturday, July 30, 2016

Pass or Fail Grade Checker Using Ternary Operator in C++

Here is a sample program that I wrote in C++ to check if the given grade of the student is pass or failed using ternary operator in C++.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing

#include <iostream>

 using namespace std;

main() {

    int grade=0;

    cout << " Conditional Operator Demo (?:) ";
    cout << "\n\n";
    cout << "Enter your grade : ";
    cin >> grade;
    cout << "\n\n";
    cout << (grade >= 75 ? "You Passed." : "You Failed.");
    cout << "\n\n";
     if (grade >= 75) {
         cout << "You Passed.";
     }
     else {
         cout << "You Failed.";
     }
    cout << "\n\n";
    system("pause");
}

No comments:

Post a Comment