I have been learning Objective-C with the Kochan book and I can't figure out how to do this exercise program. Only odd numbered exercises are listed online and this one is even. The exercise is to convert numbers into words. So, if "932" was entered, the program should return: "nine three two"
I used a do
, while
loop but the words came out backwards, as in "two three nine". Can anyone suggest a technique that works for this?
int number, digit;
NSLog(@"Type in your integer.");
scanf("%i", &number);
do
{
digit = number % 10;
if (digit == 0)
NSLog(@"zero");
if (digit == 1)
NSLog(@"one");
if (digit == 2)
NSLog(@"two");
if (digit == 3)
NSLog(@"three");
if (digit == 4)
NSLog(@"four");
if (digit == 5)
NSLog(@"five");
if (digit == 6)
NSLog(@"six");
if (digit == 7)
NSLog(@"seven");
if (digit == 8)
NSLog(@"eight");
if (digit == 9)
NSLog(@"nine");
number /= 10;
}
while (number != 0);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…