#import "CalcViewController.h" @implementation CalcViewController @synthesize textField1; @synthesize button1; @synthesize button2; @synthesize button3; @synthesize button4; @synthesize button5; @synthesize button6; @synthesize button7; @synthesize button8; @synthesize button9; //@synthesize button0; @synthesize pls; @synthesize mns; @synthesize mul; @synthesize div; @synthesize back_space; @synthesize equals; @synthesize cancel; @synthesize decimal_point; //@synthesize button2; //NSString result; //NSString currentNumber = @"0"; //int iNumber; int operator=0; int first; int second; //NSString *myString = @"9";// = [NSString string]; /* -(IBAction) Plus:(id)sender { textField1.text=@"0"; }*/ -(IBAction) b0:(id)sender { //iNumber = [currentNumber intValue]; //iNumber = iNumber * 10 + 0; myString = [myString stringByAppendingString:@"0"];//textField1.text;//, intValue]; textField1.text=myString; //currentNumber=currentNumber * 10 + 0; //NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber]; //textField1.text= [NSString stringWithFormat:@"%@",myString]; } -(IBAction) b1:(id)sender { myString=[myString stringByAppendingString:@"1"]; textField1.text=myString; //currentNumber=currentNumber * 10 + 1; //NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber]; //textField1.text= [NSString stringWithFormat:@"%@",myString]; } -(IBAction) b2:(id)sender { myString=[myString stringByAppendingString:@"2"]; textField1.text=myString; //currentNumber=currentNumber * 10 + 2; //NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber]; //textField1.text= myNewString; } -(IBAction) b3:(id)sender { myString=[myString stringByAppendingString:@"3"]; textField1.text=myString; /*currentNumber=currentNumber * 10 + 3; NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber]; textField1.text= myNewString;*/ } -(IBAction) b4:(id)sender { myString=[myString stringByAppendingString:@"4"]; textField1.text=myString; /*currentNumber=currentNumber * 10 + 4; NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber]; textField1.text= myNewString;*/ } -(IBAction) b5:(id)sender { myString=[myString stringByAppendingString:@"5"]; textField1.text=myString; /*currentNumber=currentNumber * 10 + 5; NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber]; textField1.text= myNewString;*/ } -(IBAction) b6:(id)sender { myString=[myString stringByAppendingString:@"6"]; textField1.text=myString; /*currentNumber=currentNumber * 10 + 6; NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber]; textField1.text= myNewString;*/ } -(IBAction) b7:(id)sender { myString=[myString stringByAppendingString:@"7"]; textField1.text=myString; /*currentNumber=currentNumber * 10 + 7; NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber]; textField1.text= myNewString;*/ } -(IBAction) b8:(id)sender { myString=[myString stringByAppendingString:@"8"]; textField1.text=myString; /*currentNumber=currentNumber * 10 + 8; NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber]; textField1.text= myNewString;*/ } -(IBAction) b9:(id)sender { myString=[myString stringByAppendingString:@"9"]; textField1.text=myString; /*currentNumber=currentNumber * 10 + 9; NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber]; textField1.text= myNewString;*/ } -(IBAction) plus:(id)sender { operator=1; first=[textField1.text intValue]; myString=@""; } -(IBAction) minus:(id)sender { operator=2; first=[textField1.text intValue]; myString=@""; } -(IBAction) multiply:(id)sender { operator=3; first=[textField1.text intValue]; myString=@""; } -(IBAction) divide:(id)sender { operator=4; first=[textField1.text intValue]; myString=@""; } switch (operator) { case 1: { first; break; } default: first; } /* if (operator == 1) { second=[textField1.text, intValue]; first=first+second; textField1.text=first; }*/ // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; myString = @""; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end
switch (operator) { case 1: { first; break; } default: first; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)