Amazon.com Widgets Chapter 6, Exercise 6
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 18, 2013, 08:13:40 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 6
| | | |-+  Chapter 6, Exercise 6
Pages: [1]   Go Down
Print
Author Topic: Chapter 6, Exercise 6  (Read 467 times)
CloudDweller
Newbie
*
Posts: 17






« on: February 14, 2012, 12:05:44 PM »

Okay this one took me ages and I mean ages.  My first attempt can be found here http://classroomm.com/objective-c/index.php?topic=6714.0

and as you'll see it took me a while to get my head around it.  All I can say is that if you stick at it, you'll get there in the end and if not, re-reading chapters really helps to cement stuff and if you're still stuck there's plenty of help available in these forums.

Thanks again Steve  Grin

Code: (Objective-C)
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

    @autoreleasepool {
        
        int  number, counter;
        
        NSLog (@"Enter your number.");
        scanf ("%i", &number);
        
        for (counter = 1; (number / counter) > 9; counter *= 10);   // while number divided by counter is greater than 9, mutiply counter by 10 and assign value back to counter
        for (; counter > 0; counter /= 10) {                        // while counter is greater than 0 execute the loop and then divide counter by 10
            switch ((number / counter) % 10) {                      // divide number by counter and then divide again by 10 using the modulus operator
                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;
                default:
                    break;
            }
        }
    }
    return 0;
}
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.