#include using namespace std; bool is_2 (int); bool is_even (int); //******************************************************* // some boolean functions, the conditional operator, and boolalpha int main() { int x, y, z; x = 2; y = 4; z = 5; if (is_even (z)) cout << z << " is even" << endl; else cout << z << " is odd" << endl; cout << endl; cout << x << " is 2: " << is_2(x) << endl; cout << y << " is 2: " << is_2(y) << endl; cout << endl; cout << x << " is 2: " << (is_2(x) ? "true" : "false") << endl; cout << y << " is 2: " << (is_2(y) ? "yes" : "no") << endl; cout << endl; cout << x << " is 2: " << boolalpha << is_2(x) << endl; return 0; } //******************************************************* bool is_2 (int i) { bool result; result = (i == 2); return result; } bool is_even (int i) { bool result; result = (i%2 == 0); return result; } /* alternate code: if (i%2 == 0) return true; else return false; */ /******************************************************* 5 is odd 2 is 2: 1 4 is 2: 0 2 is 2: true 4 is 2: no 2 is 2: true */