C++ if statement with else on a numerical value

Description

C++ if statement with else on a numerical value

#include <iostream>

int main()/*from   ww  w.ja v  a  2s  .c  o  m*/
{
  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;
  }
}



PreviousNext

Related