I have a conditional statement to check if a number is odd or even in PHP
<?php
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d
", $N);
fclose($stdin);
function weird_or_not($N) {
//check that n is between 1 and 100
if ($N >= 1 && $N <= 100) {
//check if n is even
if ($N % 2 == 0) {
// check if n is in the inclusive range 2 - 5
if ($N >= 2 && $N <= 5) {
echo 'Not Weird';
}
// check if n is in the inclusive range 6 - 20
elseif ($N >= 6 && $N <= 20) {
echo 'Weird';
}
// check if n is greater than 20
elseif ($N > 20) {
echo 'Not Weird';
}
}
// otherwise n is odd
else {
echo 'Weird';
echo $N % 2;
}
}
}
echo weird_or_not($stdin);
?>
When I have an input of an even number it prints out 'Weird', and when I print out $N % 2, for any even number it gives the result as 1 when it should be 0. So why is an even number modulo 2 returning 1 when it should return 0?