I am trying to learn how to call and write functions using an old book, "C By Discovery" It is a good book.
My problem is the following code returns the 'odd' message only on the numbers 3, and 11. At times the prog will return others but they aren`t consistent and I haven`t gotten 9, 17, and 19 to show up as odd at all.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int inputint;
printf ("Enter a positive even ");
printf ("number that is less than 20.\n");
scanf ("%d", &inputint);
if (inputint < 20) {
if ( odd(inputint) )
printf ("Sorry that number wasn`t even.\n");
else if (inputint <= 0)
printf ("That number wasn`t positive.\n");
}
else
printf ("That number was too big.\n");
system("PAUSE");
return 0;
}
/* ******************odd***************************** */
/* odd() returns a 1 if intvar is odd
*/
odd (int intvar)
{
return(intvar & 2);
}
I`m using CodeBlocks with Mingw compiler. I also tried this on DevC++ and it does the same thing. The compiler griped right at first that I was using an 'implicit' function but then carried on to run the program with the above mysteries.
Is this because this 'odd' function is an implicit function? If so how do I make it an explict function?
Thanks, Plain