A garbage Calculator

Source: Internet
Author: User

//

// 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 {

// Calculation Result

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

{

Cal. opsb = 0;

Cal. opvalue1 = 0;

Cal. opvalue2 = 0;

Self. Lab. Text = [nsstring stringwithformat: @ "0"];

}

 

@ End

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.