I am reading the Stephen G. Kochan book about obj-c and in the end of every chapter, there are few exercises to train what have you learned so far.
I am having a little problem with one exercise where I am supposed to write a small program to convert digits to words. (input: 34524, output: three four five two four) I tried searching google but there are just examples for rewriting number to text (1423, one thousand four hundred twenty three).
I only figured out how to rewrite it backwards like (4213, three one two four), but can't figure out how to save the digits from the front to back.
Here's the backwards program:
Thank you for help.
I am having a little problem with one exercise where I am supposed to write a small program to convert digits to words. (input: 34524, output: three four five two four) I tried searching google but there are just examples for rewriting number to text (1423, one thousand four hundred twenty three).
I only figured out how to rewrite it backwards like (4213, three one two four), but can't figure out how to save the digits from the front to back.
Here's the backwards program:
Code:
#import <Foundation/Foundation.h>
int main (int argc, char *argv [])
{
@autoreleasepool {
int number, enddigit;
NSLog(@"Type a number");
scanf("%i", &number);
for (; number % 10 != 0; number /= 10){
enddigit = number % 10;
switch (enddigit){
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;
case (0):
NSLog(@"zero");
break;
}
}
}
return 0;
}
Thank you for help.
Last edited: