So I have this book by Kochan, Programming in Objective - C. I was trying to do an excerise, but I just couldn't get it.
Its making a thing where you enter a number, say 893. Then it returns the numbers in order, but in English.
So I enter 893, it returns:
eight
nine
three.
So I got something like it:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int number, right_digit;
NSLog(@"Type in your integer.");
scanf("%i", &number);
for (right_digit = number % counter ; number > 0; number /= 10, right_digit = number % 10) {
if (right_digit == 0)
NSLog (@"zero");
else if (right_digit == 1)
NSLog (@"one");
else if (right_digit == 2)
NSLog (@"two");
else if (right_digit == 3)
NSLog (@"three");
else if (right_digit == 4)
NSLog (@"four");
else if (right_digit == 5)
NSLog (@"five");
else if (right_digit == 6)
NSLog (@"six");
else if (right_digit == 7)
NSLog (@"seven");
else if (right_digit == 8)
NSLog (@"eight");
else if (right_digit == 9)
NSLog (@"nine");
else
NSLog (@"zero");
}
[pool drain];
return 0;
}
But instead if I enter 893, it returns
three
nine
eight.
I cant reverse it... Maybe there is a way using arrays?
Please help XD Thanks.
Its making a thing where you enter a number, say 893. Then it returns the numbers in order, but in English.
So I enter 893, it returns:
eight
nine
three.
So I got something like it:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int number, right_digit;
NSLog(@"Type in your integer.");
scanf("%i", &number);
for (right_digit = number % counter ; number > 0; number /= 10, right_digit = number % 10) {
if (right_digit == 0)
NSLog (@"zero");
else if (right_digit == 1)
NSLog (@"one");
else if (right_digit == 2)
NSLog (@"two");
else if (right_digit == 3)
NSLog (@"three");
else if (right_digit == 4)
NSLog (@"four");
else if (right_digit == 5)
NSLog (@"five");
else if (right_digit == 6)
NSLog (@"six");
else if (right_digit == 7)
NSLog (@"seven");
else if (right_digit == 8)
NSLog (@"eight");
else if (right_digit == 9)
NSLog (@"nine");
else
NSLog (@"zero");
}
[pool drain];
return 0;
}
But instead if I enter 893, it returns
three
nine
eight.
I cant reverse it... Maybe there is a way using arrays?
Please help XD Thanks.