What's wrong with the code below?

0

When I clicked on "Run" in Xcode to run the code and see if everything is right, I said "Build Succeeded", but in the code output the following appears:

  

2015-12-11 17: 35: 38,289 prog1 [36561: 1080062] The value of myfraction   is: (lldb)

Should not this appear? :

  

2015-12-11 17: 35: 38,289 prog1 [36561: 1080062] The value of myfraction   is: 1/3.

Follow the code.

#import <Foundation/Foundation.h>

@interface Fraction : NSObject

-(void) print;  
-(void) setnumerator: (int) n;  
-(void) setdenominatior: (int) d;  

@end  

@implementation Fraction  
{  
    int numerator;  
    int denominatior;  
}  
-(void) print  
{  
    NSLog(@"%i/%i", numerator, denominatior);  
}  
-(void) setnumerator:(int) n  
{  
    numerator = n;  
}  
-(void) setdenominatior:(int) d  
{  
    denominatior = d;  
}  
@end


int main(int argc, const char * argv[])  
{
    @autoreleasepool {  
        Fraction *myFraction;  

        myFraction = [Fraction alloc];  
        myFraction = [myFraction init];  

        [myFraction setnumerator: 1];  
        [myFraction setdenominatior: 3];  

        NSLog(@"The value of myfraction is:");  
        [myFraction print];  

    }  
    return 0;
}  
    
asked by anonymous 11.12.2015 / 21:41

1 answer

1

To print an integer you should use% d, not% i, as well as C. In this case your print should look like this:

NSLog(@"%d/%d", numerator, denominatior);  
    
11.10.2016 / 18:45