Saturday, July 30, 2016

Ternary Operator in C++

Here is a sample program that I wrote in C++ to show how to use ternary operator. The code is very simple and easy to understand.

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() {
  for(;;) {
    int number=0,value=0;

    system("cls");
    cout << "Enter a Number :=> ";
    cin >> number;

    if (number==0) {
         cout << "\n\n";
         cout << "\t Thank You For Using This Program";
         break;
     }
      value = (number >=10 ? 20:10);

      cout << "\n\n";
      cout << "The resulting value is "
           << value << ".";
     cout << "\n\n";
     system("pause");

   }
      cout << "\n\n";
      system("pause");
}


1 comment:

  1. This is my passion and i have also a lot of tutorials about this topic and your salon and work is good. Thank you very for share us such kind of good info

    ReplyDelete