C++ if statement to range check the value of an integer entered from the keyboard

Description

C++ if statement to range check the value of an integer entered from the keyboard

#include <iostream>

int main()//from  w  w  w. j  a  v  a 2 s . co  m
{
  std::cout << "Enter an integer between 50 and 100: ";

  int value {};
  std::cin >> value;

  if(value < 50)
    std::cout << "The value is invalid - it is less than 50." << std::endl;

  if(value > 100)
    std::cout << "The value is invalid - it is greater than 100." << std::endl;

  std::cout << "You entered " << value << std::endl;
}



PreviousNext

Related