An example of using if-else with a numerical value - C++ Statement

C++ examples for Statement:if

Description

An example of using if-else with a numerical value

Demo Code

#include <iostream>

int main()//from   w  w  w  .  j  a  v a  2  s.  com
{
  long number {};                            // Stores input
  std::cout << "Enter an integer less than 2 billion: ";
  std::cin >> number;

  if(number % 2L) // Test remainder after division by 2
  { // Here if remainder is 1
    std::cout << "Your number is odd." << std::endl;
  }
  else
  { // Here if remainder is 0
    std::cout << "\nYour number is even." << std::endl;
  }
}

Result


Related Tutorials