PDA

View Full Version : Objective C Help




Furtim
Jul 8, 2008, 11:45 PM
#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.



CaptainZap
Jul 9, 2008, 12:01 AM
What data type are the Fiber, Points, etc? Like NSNumber, int?

lee1210
Jul 9, 2008, 12:03 AM
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

Furtim
Jul 9, 2008, 12:06 AM
Fiber, Points, etc are what the textfields are called under outlets...not sure if that answers your question.

Furtim
Jul 9, 2008, 12:16 AM
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

aLoC
Jul 9, 2008, 12:17 AM
You should use iCal iFiber etc in that final calculation.

Furtim
Jul 9, 2008, 12:22 AM
Oh, okay I got it. Thanks everyone.

pravara15
Oct 8, 2009, 04:31 AM
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.