performance/perf-cpp/scripts/ch6.cc

20 lines
643 B
C++

#include <iostream>
#include <cstdint>
/*
Write a program that asks the user to input an integer, and tells the user whether the number is even or odd. Write a constexpr function called isEven() that returns true if an integer passed to it is even, and false otherwise. Use the remainder operator to test whether the integer parameter is even. Make sure isEven() works with both positive and negative numbers
.*/
constexpr bool isEven(std::int32_t number) {
return number % 2 == 0;
}
int main() {
std::cout << "input an integer: \n";
std::int32_t x{};
std::cin >> x;
std::cout << std::boolalpha << isEven(x);
return 0;
}