首页 > 代码库 > 简单计算器

简单计算器

#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

  

简单计算器