+ 3
#include <iostream> using namespace std; // other way around, I was wrong bool odd(const char x) { return x%2; } int main() { char c = 23; if (odd(c)) cout << "odd"; else cout << "even"; }
3rd Feb 2018, 2:59 PM
Timon Paßlick
+ 6
if (n%2 == 0) ; //even else ; //odd n%2 == 1
3rd Feb 2018, 1:48 PM
John Wells
John Wells - avatar
+ 4
char is a form of int so this works for it too
3rd Feb 2018, 1:50 PM
John Wells
John Wells - avatar
+ 4
char n = '7'; if (n%2 == 0) // perfectly legal n = 5;
3rd Feb 2018, 1:53 PM
John Wells
John Wells - avatar
+ 1
bool even(const char x) { return x%2; } bool odd(const char x) { return !even(x) }
3rd Feb 2018, 1:53 PM
Timon Paßlick
0
Cool, so it's solved.
3rd Feb 2018, 1:55 PM
Timon Paßlick
- 1
bool even(int x) { return x%2; } Is this what you need?
3rd Feb 2018, 1:49 PM
Timon Paßlick
- 1
Do you want to check if a char is even or odd?
3rd Feb 2018, 1:51 PM
Timon Paßlick
- 1
Is if-else really required?
3rd Feb 2018, 1:52 PM
Timon Paßlick