1. Answer: Use X-Code to type in the following programs: Page 7 Program 2.1; Page 22 Program 2.2; Page 23 Program 2.3; Page 23 Program 2.4; Page Program 2.5. Build/Run and see the output in the debug window at the bottom. Change your view to display if no debug window is showing up.
2. Answer: Not really a question.
3. Answer: NSLog will display "Testing......1...2...3" in the debug window.
4. Answer:
//
// main.m
// prog11
//
// Created by BlueBirdApps.com on 4/7/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
int a, b, answer;
a = 15;
b = 87;
NSLog(@"The difference between %i and %i is %i", a, b, (b-a));
}
return 0;
}
5. Answer:
> INT should be lowercase.
> "/* COMPUTE RESULT//" comment should be "//COMPUTE RESULT" or "/*COMPUTE RESULT */"
>"/DISPLAY RESULTS/" comment should be "//DISPLAY RESULT" or "/*DISPLAY RESULT*/"
6. Answer: 95 (100 - 10 +5)
Thanks for starting this out, but I found something that needs attention,
NO.3:
my output is:
2012-07-02 11:26:41.223 prog1[8011:403] Testing...
2012-07-02 11:26:41.224 prog1[8011:403] ....1
2012-07-02 11:26:41.225 prog1[8011:403] ...2
2012-07-02 11:26:41.225 prog1[8011:403] ..3
and on the no.4, in mathematics, it isn't grammatically correct:
NSLog(@"The difference between %i and %i is %i", a, b, (b-a));
Output: "The difference between 15 and 87 is 72
If interpreted & performed in elementary mathematics, the result is -72.
Back to the instruction:
4. Write a program that subtracts the value 15 from 87 and displays the result, together with an "appropriate message".
Thus, the "appropriate message" must be:
"The difference between 87 and 15 is 72"
Code: NSLog(@"The difference between %i and %i is %i", b, a, (b-a));