首页 > 代码库 > 简单计算器
简单计算器
#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
简单计算器
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。