Tutorial details

Basic Calculator | App Code for Sale | Preview

Basic Calculator | iOS Tutorial

How to create a basic calculator

Overview PAGE TOP

Reference: http://www.geekylemon.com/WEBPROTECT-xcodebasiccalculator.htm

In this tutorial i will be showing you how to create a basic calculator

Features:

  • 1 Label
  • 17 Round Rect Buttons

This tutorial is a full featured app allowing you to add, minus, divide and multiply once created it can be ready to be submitted to the app store or you could expand on it and give it you own personal touch

ViewController.h PAGE TOP

@interface ViewController :UIViewController {
float result;
IBOutlet UILabel *calculatorScreen;
int currentOperation;
float currentNumber;
}
-(IBAction)buttonDigitPressed:(id)sender;
-(IBAction)buttonOperationPressed:(id)sender;
-(IBAction)cancelInput;
-(IBAction)cancelOperation;
@end

ViewController.m PAGE TOP

@implementation ViewController
-(IBAction)buttonDigitPressed:(id)sender {
currentNumber = currentNumber*10 + (float)[sender tag];
calculatorScreen.text = [NSString stringWithFormat:@"%2f",currentNumber];
}
-(IBAction)buttonOperationPressed:(id)sender {
if (currentOperation == 0) result = currentNumber;
else {
switch (currentOperation) {
case 1:
result = result + currentNumber;
break;
case 2:
result = result - currentNumber;
break;
case 3:
result = result * currentNumber;
break;
case 4:
result = result / currentNumber;
break;
case 5:
currentOperation = 0;
break;
}
}
currentNumber = 0;
calculatorScreen.text = [NSString stringWithFormat:@"%2f",result];
if ([sender tag] == 0) result = 0;
currentOperation = [sender tag];
}
-(IBAction)cancelInput {
currentNumber = 0;
calculatorScreen.text = @"0";
}
-(IBAction)cancelOperation {
currentNumber = 0;
calculatorScreen.text = @"0";
currentOperation = 0;
}
@end

Reference PAGE TOP

http://www.geekylemon.com/WEBPROTECT-xcodebasiccalculator.htm

0 Comments Leave a comment

Please login in order to leave a comment.

Newest first
!

Sign-in to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.