4 points
23 points
*
I know how to fix this!
bool IsEven(int number) {
bool even = true;
for (int i = 0; i < number; ++i) {
if (even == true) {
even = false;
}
else if (even == false) {
even = true;
}
else {
throw RuntimeException("Could not determine whether even is true or false.");
}
}
if (even == true) {
return even ? true : false;
}
else if (even == false) {
return (!even) ? false : true;
}
else {
throw RuntimeException("Could not determine whether even is true or false.");
}
}
7 points
13 points
modulo
pseudocode:
if number % 2 == 0
return "number is even" (is_num_even = 1 or true)
else
return "number is odd" (is_num_even = 0 or false)
plus you’d want an input validation beforehand
23 points
*
who needs modulo when you can get less characters out of
while (number > 1) {
number -= 2;
}
return number;
very efficient
edit: or theres the trusty iseven api
9 points
10 points
4 points
2 points
2 points
7 points
3 points
4 points
#You are an input. You have value! You matter!
if number % 2 == 0
return "number is even" (is_num_even = 1 or true)
else
return "number is odd" (is_num_even = 0 or false)
Am I doing it right? /S.
5 points
2 points
This code is terrible. If you input 10.66 it returns "number is odd
It should be:
if number % 2 == 0
return "number is even" (is_num_even = 1 or true)
else
return "number is not even" (is_num_even = 0 or false)
1 point
Modulo
6 points
3 points
7 points
Deleted by creator