i reading stephen g. kochan book obj-c , in end of every chapter, there few exercises train have learned far.
having little problem 1 exercise supposed write small program convert digits words. (input: 34524, output: 3 4 5 2 four) tried searching google there examples rewriting number text (1423, 1 thousand 4 hundred twenty three).
figured out how rewrite backwards (4213, 3 1 2 four), can't figure out how save digits front back.
here's backwards program:
thank help.code:#import <foundation/foundation.h> int main (int argc, char *argv []) { @autoreleasepool { int number, enddigit; nslog(@"type number"); scanf("%i", &number); (; 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; }
i don't have particular book using, i'd guess question part of book.
if so, shouldn't try find way save words after converting them digits, rather find way convert significant digit first, , on.
code now, happens when input example 10 or 100? or number containing zero?
Forums iPhone, iPad, and iPod Touch iOS Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
No comments:
Post a Comment