i write my first try in objective -c , my project add two numbers take from user number 1 & number 2
and return the result
but my result always of adding = 0
this my error what ever i change numbeer1 , number2 , the result value =0 , why can any one help me?
look at my code and help me plz .
i write a class called calc
---------------------------------------------------------------
calc.h
#import <Foundation/Foundation.h>
@interface Calc : NSObject {
@public
double value1 , value2 , value3 ,result ;
@private
}
-(double) add_two_numbers : (double) X : (double) Y ;
@end
----------------------------------------------------------------
calc.m
#import "Calc.h"
@implementation Calc
-(double)add_two_numbers:(double)X :(double)Y
{
return (X + Y);
}
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
@end
----------------------------------------------------------------
main.m
#import <Foundation/Foundation.h>
#import "Calc.h"
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Calc * mycalc =[[Calc alloc]init];
double x,y;
NSLog(@"Enter the X value : ");
scanf("%f",&x);
NSLog(@"Enter the Y value : ");
scanf("%f",&y);
double z =100.0;
z=[mycalc add_two_numbers:x :y];
NSLog(@"Hello, World!");
NSLog(@"theresult = %f",z);
// insert code here...
[ mycalc release];
[pool drain];
return 0;
}