码迷,mamicode.com
首页 > 其他好文 > 详细

简单计算器

时间:2014-09-17 21:45:22      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:blog   io   os   ar   for   div   sp   cti   log   

#import "ViewController.h"







@interface ViewController ()

{

    char op1;

    NSString  *op3, *op4;

}

@property (weak, nonatomic) IBOutlet UILabel *resultLabel;





@end



@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

   op3=@‘‘;
   op4=@‘‘;

}

- (IBAction)button1clicked:(id)sender {

    NSLog(@"1 clicked");

    

    if (op1!=‘+‘&&op1!=‘-‘&&op1!=‘*‘&&op1!=‘/‘)



    {

    op3=[NSString stringWithFormat:@"%@%d",op3,1];

    }

    else

         {

    op4=[NSString stringWithFormat:@"%@%d",op4,1];

         }

}

- (IBAction)button2clicked:(id)sender {

    NSLog(@"2 clicked");

    if (op1!=‘+‘&&op1!=‘-‘&&op1!=‘*‘&&op1!=‘/‘)

        

    {

        op3=[NSString stringWithFormat:@"%@%d",op3,2];

    }

    else

    {

        op4=[NSString stringWithFormat:@"%@%d",op4,2];

    }

}

- (IBAction)button3clicked:(id)sender {

    NSLog(@"3 clicked");

    if (op1!=‘+‘&&op1!=‘-‘&&op1!=‘*‘&&op1!=‘/‘)

        

    {

        op3=[NSString stringWithFormat:@"%@%d",op3,3];

    }

    else

    {

        op4=[NSString stringWithFormat:@"%@%d",op4,3];

    }

    

    

}



- (IBAction)multclicked:(id)sender {

    op1=‘*‘;

}

- (IBAction)equalclicked:(id)sender {

    if (op1==‘*‘)

    {

        long a1=[op3 intValue];

        long a2=[op4 intValue];

        long mult=a1*a2;

        NSLog(@"%ld",mult);

        NSString *result = [NSString stringWithFormat:@"%ld",mult];

        self.resultLabel.text=result;

    }

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end

  

简单计算器

标签:blog   io   os   ar   for   div   sp   cti   log   

原文地址:http://www.cnblogs.com/diyigechengxu/p/3978104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!