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

一个垃圾计算器

时间:2014-07-16 20:32:28      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:blog   http   os   2014   for   io   

//

//  ViewController.m

//  calculator

//

//  Created by apple on 14-7-10.

//  Copyright (c) 2014年 apple. All rights reserved.

//

 

#import "ViewController.h"

#import "calculat.h"

@interface ViewController ()

{

    float result;

    int i;

}

            

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

 

@end

 

@implementation ViewController

            

- (void)viewDidLoad

{

    [super viewDidLoad];

    cal = [[calculat alloc] init];

    

}

- (IBAction)click:(UIButton *)sender

 

{

    NSLog(@"%d, %@", sender.tag, sender.currentTitle);

 // self.lab.text = [NSString stringWithFormat:@"%d", sender.tag];

    if (cal.opsb == ‘+‘

        ||cal.opsb==‘-‘

        ||cal.opsb==‘/‘

        ||cal.opsb==‘*‘)

    {

        cal.opvalue2 = cal.opvalue2 * 10 + sender.tag;

        self.lab.text = [NSString stringWithFormat:@"%f",cal.opvalue2];

       

    }

    else

    {

        cal.opvalue1 = cal.opvalue1 * 10 + sender.tag;

       self.lab.text = [NSString stringWithFormat:@"%f",cal.opvalue1];

        

    }

}

- (IBAction)sb:(id)sender{cal.opsb=‘+‘;

    

self.lab.text = [NSString stringWithFormat:@"+"];

    i=1;

    

}

- (IBAction)sbm:(id)sender{cal.opsb=‘-‘;

    

    self.lab.text = [NSString stringWithFormat:@"-"];

    i=2;

}

- (IBAction)sbc:(id)sender {cal.opsb=‘/‘;

    

    self.lab.text = [NSString stringWithFormat:@"/"];

    i=3;

 

}

- (IBAction)sbh:(id)sender {cal.opsb=‘*‘;

    

    self.lab.text = [NSString stringWithFormat:@"*"];

    i=4;

 

}

- (IBAction)didClickedEqual:(id)sender {

    

    //计算结果

    if(i==1)

    {

     result = [cal work1];

    self.lab.text  = [NSString stringWithFormat:@"%f", result];

    }

    

    else if(i==2)

    {

        result = [cal work2];

        self.lab.text  = [NSString stringWithFormat:@"%f", result];

    }

    

    else if(i==3)

    {

        result = [cal work3];

        self.lab.text  = [NSString stringWithFormat:@"%f", result];

    }

    

   else  if(i==4)

    {

        result = [cal work4];

        self.lab.text  = [NSString stringWithFormat:@"%f", result];

    }

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (IBAction)cd:(id)sender

{

bubuko.com,布布扣    cal.opsb = 0;

    cal.opvalue1 = 0;

    cal.opvalue2 = 0;

    self.lab.text  = [NSString stringWithFormat:@"0"];

    

}

 

@end

 

一个垃圾计算器,布布扣,bubuko.com

一个垃圾计算器

标签:blog   http   os   2014   for   io   

原文地址:http://www.cnblogs.com/niang123/p/3836646.html

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