Objective C Help

Discussion in 'Mac Programming' started by Furtim, Jul 8, 2008.

  1. Furtim macrumors member

    Joined:
    Jul 8, 2008
    #1
    #import "AppController.h"

    @implementation AppController
    - (IBAction)Calculate:(id)sender {
    if (Fiber >= 4){

    Fiber = 4;
    }
    Points = ( Calories / 50 ) + ( Fat / 12 ) - ( Fiber / 5 );
    }
    @end

    I'm trying to make a Weight Watchers calculator and I keep coming up with errors. I'm not sure what I'm doing wrong....

    I'm getting errors after if (Fiber >= 4){ saying warning: comparison between pointer and integer

    Also getting errors after Fiber = 4; saying warning: assignment makes pointer from integer without a cast

    And last errors after Points = ( Calories / 50 ) + ( Fat / 12 ) - ( Fiber / 5 ); saying error: invalid operands to binary /

    Any help would be grateful. Thank you.
     
  2. CaptainZap macrumors regular

    Joined:
    Jan 17, 2007
    #2
    What data type are the Fiber, Points, etc? Like NSNumber, int?
     
  3. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    from the warnings and errors, I'd say Fiber is declared as a int * instead of int. If it is a pointer and needs to be you need to dereference Fiber before using its value in an expression.

    -Lee
     
  4. Furtim thread starter macrumors member

    Joined:
    Jul 8, 2008
    #4
    Fiber, Points, etc are what the textfields are called under outlets...not sure if that answers your question.
     
  5. Furtim thread starter macrumors member

    Joined:
    Jul 8, 2008
    #5
    Okay, I understood what you meant I got now...

    #import "AppController.h"

    @implementation AppController
    - (IBAction)Calculate:(id)sender {
    double iCal, iFat, iFiber, iPoints;
    iCal = [Calories doubleValue];
    iFat = [Fat doubleValue];
    iFiber = [Fiber doubleValue];
    if (iFiber > 4)
    iFiber = 4;
    iPoints = (Calories / 50) + (Fat / 12) - (Fiber / 5);
    }
    @end

    Everything runs fine except I get an error for the iPoints = (Calories / 50) + (Fat / 12) - (Fiber / 5); line
     
  6. aLoC macrumors 6502a

    Joined:
    Nov 10, 2006
    #6
    You should use iCal iFiber etc in that final calculation.
     
  7. Furtim thread starter macrumors member

    Joined:
    Jul 8, 2008
  8. pravara15 macrumors newbie

    Joined:
    May 14, 2009
    #8
    Assignment makes integer from pointer without a cast

    Hi,
    In Objective-c, I have one function which accepts int as parameter, viz:
    -(void)Sum:(int)i{
    Sum = i+10;
    }

    where 'Sum' is static variable declared globally, int he same .m file.
    now, I am calling this 'Sum' function from some other function as follows:
    -(void)Funct{
    int i = 10;
    [self Sum:i];
    }

    After **[self Sum:i];** i get warning saying:
    "assignment makes integer from pointer without a cast"


    I am not getting where is the mistake. Please let me know as soon as possible.

    Thanx.
     

Share This Page