“Write a program that takes an integer keyed in from the terminal and extracts and
displays each digit of the integer in English. So if the user types in 932, the program
should display the following:
nine
three
two
(Remember to display zero if the user types in just 0.)”
Here is my solution. Xcode doesn’t do anything after i type in number. (My mistake is the code is written to show digits in reverse)
Can you help me out? where is the mistake?
#import <Foundation/Foundation.h>
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int number, right_digit;
NSLog (@"Enter your number.");
scanf ("%i", &number);
do {
right_digit = number % 10;
switch (right_digit) {
case '0':
Nslog (@"zero");
break;
case '1':
NSLog(@"one");
break;
case '2':
NSLog(@"two");
break;
case '3':
NSLog(@"three");
break;
case '4':
NSLog(@"four");
break;
case '5':
NSLog(@"five");
break;
case '6':
NSLog(@ "six");
break;
case '7':
NSLog(@"seven");
break;
case '8':
NSLog(@"eight");
break;
case '9':
NSLog(@"nine");
break;
default:
break;
}
number /= 10;
}
while ( number != 0 );
[pool drain];
return 0;
}
The character
'0'is different than the number0.