Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
December 10, 2018, 03:40:18 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: program 3.2  (Read 4394 times)
michaelangelo
Newbie
*
Posts: 29


Email
« on: February 14, 2014, 03:47:16 PM »

I type the prgram exactly as it states. I get no errors but it prints

The value of myFraction is:
(lldb)

#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 (@"%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 *myFraction;
       
        //Create an instance of a fraction //
       
        myFraction = [Fraction alloc];
        myFraction = [myFraction init];
       
        //Set fraction to 1/3//
       
        [myFraction setNumerator: 1];
        [myFraction setDenominator: 3];
       
        //-----Display the fraction using the print method----//
       
        NSLog (@"The value of myFraction is:");
        [myFraction print];
    }
    return 0;
}
Logged
michaelangelo
Newbie
*
Posts: 29


Email
« Reply #1 on: February 14, 2014, 03:50:32 PM »

NSLog (@"%i/%i", numerator, denominator);

thats the line where its highlights green. Says thread 1: breakpoint 1.1 If i right click the text and click continue to here it runs as it should. But if i press run again it comes back with (lldb)

thank you to anyone who can help
Logged
BrianLawson
Sr. Member
****
Posts: 262


Email
« Reply #2 on: February 14, 2014, 05:24:53 PM »

lldb is the debugger. It sounds like you have a checkpoint set at the NSLog line. Look for a blue arrow marker just to the left of that line in the editor. If you see it, drag it out of the gutter to get rid of it then run your program again.
Logged
michaelangelo
Newbie
*
Posts: 29


Email
« Reply #3 on: February 14, 2014, 07:00:21 PM »

Thank you so much!

I appreciate you taking the time.
Logged
pezak
Newbie
*
Posts: 1


Email
« Reply #4 on: January 13, 2015, 03:52:24 PM »

Hello, after I type the program exactly as stated using the code below:

 @interface Fraction: NSObject                        //Line 1

        - (void) print();                                     
        - (void) setNumerator: (int) n;                //3
        - (void) setDenominator: (int);                //4
           
        @end                                                    //5
       
I get four errors:
Line 1: Unexpected @ in program
Line 3: Use of undeclared identifier 'setNumerator'
Line 4: Use of undeclared identifier 'setNumerator'

Line 5: unexpected @ in program

I don't know what I am doing wrong build the build fails every time and I can't find a reason why.

Please clarify?
Logged
BrianLawson
Sr. Member
****
Posts: 262


Email
« Reply #5 on: January 13, 2015, 03:58:59 PM »

What type of project did you create before you started typing in the code?

What is the file extension for your source code file?
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

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 ゥ 2009 classroomM.com. All rights reserved.