A program to tell odd numbers from even. What am I doing wrong?
I’m very new to programming. I wanted to learn Objective-C, so I bought this book called +Programming in Objective-C 2.0+ by Stephen G. Kochan.
In the sixth chapter, “Making Descisions”, there is this sample program to calculate whether any given number is odd or even:
// Program to determine if a number is even or odd
#import <Foundation/Foundation.h>
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int numbertotest, remainder;
NSLog(@"Enter your number to be tested: ");
scanf("@i", &numbertotest);
remainder = numbertotest % 2;
if (remainder == 0)
NSLog(@"The number is even.");
else
NSLog(@"The number is odd.");
[pool drain];
return 0;
}This is the exact program given in the book and seems to be quite simple. However, no matter what number I enter, even or odd, it returns only the first statement, “The number is even.” What am I doing wrong?
Thanks.
MacBook Pro, Mac OS X (10.5.6)