//선언 부분
#import <Foundation/Foundation.h>
@interface cal : NSObject
{
double input_1;
double input_2;
double temp;
}
-(void) scan; // 입력
-(void) addition; //덧셈
-(void) subtraction; // 뺄셈
-(void) multiplication; // 곱셈
-(void) division; // 나눗셈
@end
//실행 부분
#import "cal.h"
@implementation cal
-(void) scan
{
scanf("%lf %lf", &input_1, &input_2);
}
-(void) addition
{
temp = input_1 + input_2;
NSLog(@"%the result is %lf", temp);
}
-(void) subtraction
{
temp = input_1 - input_2;
NSLog(@"%the result is %lf", temp);
}
-(void) multiplication
{
temp = input_1 * input_2;
NSLog(@"%the result is %lf", temp);
}
-(void) division
{
temp = input_1 / input_2;
NSLog(@"%the result is %lf", temp);
}
@end
//메인 부분
#import "cal.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
cal *mycal = [[cal alloc] init];
char calculation;
NSLog(@"연산자를 입력하세요.('+', '-', '*', '/'중 택1");
scanf("%c", &calculation);
NSLog(@"연산할 두 수를 입력하세요.");
[mycal scan];
if( calculation == '+')
{
[mycal addition];
}
else if( calculation == '-')
{
[mycal subtraction];
}
else if( calculation == '*')
{
[mycal multiplication];
}
else if( calculation =='/')
{
[mycal division];
}
else
{
NSLog(@"잘못 입력 하셨습니다.");
}
[mycal release];
[pool drain];
return 0;
}
이렇게 소스를 짰는데 값이 이상하게 나와버려서 질문드립니다.
Objective - C입니다.
의심되는 부분 정도는 표기해 주시면 더 좋을거 같은데... 질문하신걸 보자니 내가 이 소스를 분석하고 있어야하나... 하는 생각이 드네요..