Challenge 2 Solution


#1

[code]#import <Foundation/Foundation.h>
#import <stdio.h>
#import <stdlib.h>
#import <readline/readline.h>

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

@autoreleasepool {

NSString *readNum;
NSString *whoIsCool;
int num;

do {

NSLog(@"Where should I start counting? Enter a number");
readNum = [NSString stringWithUTF8String:readline(NULL)];

// Convert NSString to an int.
num = [readNum intValue];

if (num > 0)
{
for (int i = num; i > 0; i -=3)
    {
      // test if the entered value is evenly divisible by 5
      if (i % 5 == 0)
       {
         NSLog(@"%d. Found one!\n", i);
        }
      else
       {
         NSLog(@"%d.\n", i);
       }
    }
}
else
{
    NSLog(@"Please enter a number only");
}

// If the entered value is not a number, then loop to the top
// until a number is entered
} while (num == 0);

NSLog(@"Who is cool? \n");
whoIsCool = [NSString stringWithUTF8String:readline(NULL)];
NSLog(@"%@ is cool!", whoIsCool);

return 0;

}
}[/code]