Amazon.com Widgets Program 3.3 Output Issue
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 12:42:19 PM
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
|-+  Programming in Objective-C, 4th edition
| |-+  Chapter 3
| | |-+  Program 3.3 Output Issue
Pages: [1]   Go Down
Print
Author Topic: Program 3.3 Output Issue  (Read 450 times)
Kale2312
Newbie
*
Posts: 1






« on: July 24, 2012, 10:11:36 AM »

I am having some trouble with the Output area of Xcode. I'm pretty sure I have the code exactly matching what is in the book however when I Run the program it produces the following:

2012-07-24 11:06:28.332 Program 3.3[990:403]
First fraction is:
2012-07-24 11:06:28.334 Program 3.3[990:403]
2/3

It does't show anything about frac2. Am I doing something wrong? Everything I have typed is below.

//  Program 3.3

#import <Foundation/Foundation.h>

//----@interface section----

@interface Fraction: NSObject

-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;

@end

//  ----@implementation section----

@implementation Fraction

{
    int numerator;
    int denominator;
}
-(void) print
{
    NSLog (@"\n%i/%i", numerator, denominator);
}
-(void) setNumerator: (int) n
{
    numerator = n;
}
-(void) setDenominator: (int) d
{
    denominator = d;
}

@end

//  ----program section----

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

{
    @autoreleasepool {
        Fraction *frac1 = [[Fraction alloc] init];
        Fraction *frac2 = [[Fraction alloc] init];
       
        //  Set 1st fraction to 2/3
       
        [frac1 setNumerator: 2];
        [frac1 setDenominator: 3];
       
        //  Set 2nd fraction to 3/7
       
        [frac2 setNumerator: 3];
        [frac2 setDenominator: 7];
       
        //  Display the fractions
       
        NSLog (@"\nFirst fraction is:");
        [frac1 print];
       
        NSLog (@"\nSecond fraction is:");
        [frac2 print];
    }
    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.