What I'm trying to do is have the user input a number, and then the program reads each digit back in word form. For example:
Input: 517
Output: Five One Seven
It's a simple command-line tool, using NSLogs and scanf to get the input and provide output, nothing too advanced. I have the jist of it, but it only works with one-digit numbers:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
@autoreleasepool {
int number;
NSLog(@"Type your number.");
scanf("%i", &number);
if (number == 0) {
NSLog(@"Zero");
} else if (number == 1){
NSLog(@"One");
} else if (number == 2) {
NSLog(@"Two");
} else if (number == 3) {
NSLog(@"Three");
} else if (number == 4) {
NSLog(@"Four");
} else if (number == 5) {
NSLog(@"Five");
} else if (number == 6) {
NSLog(@"Six");
} else if (number == 7) {
NSLog(@"Seven");
} else if (number == 8) {
NSLog(@"Eight");
} else if (number == 9) {
NSLog(@"Nine");
}
}
return 0;
}
However, I'm having problems working with more digits. I was thinking of using something like this to split them up:
right_digit = number % 10;
NSLog(@"%i", right_digit);
number /= 10;
But that would output backwards.
Any advice?
Thanks