Get an integer from the user and check if it is divisible by 2. Print appropriate message on the screen
#include <iostream>
int main()
{
std::cout << "Please input an integer: ";
int n;
std::cin >> n;
if(!std::cin)
{
std::cerr << "Bad input\n";
return 1;
}
if(n % 2 == 0)
{
std::cout << "The integer " << n << " is divisible by 2 without remainder\n";
}
else
{
std::cout << "The integer " << n << " is divisible by 2 with remainder\n";
}
return 0;
}
Comments
Leave a comment