Finding the range for an integer with conditional operator - C++ Operator

C++ examples for Operator:Conditional Operator

Description

Finding the range for an integer with conditional operator

Demo Code

#include <iostream>
using std::cin;/*  www  .  ja v a2 s. com*/
using std::cout;
using std::endl;

int main() {
  int n = 0;
  cout << "Enter an integer: ";
  cin >> n;


  cout << "The value is "
    << (n<=20 ? "not greater than 20." : (n<=30 ? "greater than 20 and not greater than 30." :
              (n<=100 ? "greater than 30 and not exceeding 100.": "greater than 100." )))
    << endl;

  return 0;
}

Result


Related Tutorials