Skip to content

Instantly share code, notes, and snippets.

@chyld
Created August 9, 2012 16:25
Show Gist options
  • Save chyld/3305639 to your computer and use it in GitHub Desktop.
Save chyld/3305639 to your computer and use it in GitHub Desktop.
adv calc
//
// CMViewController.m
// Xcalc
//
// Created by Chyld Medford on 8/9/12.
// Copyright (c) 2012 Chyld Medford. All rights reserved.
//
#import "CMViewController.h"
@interface CMViewController ()
@end
@implementation CMViewController
@synthesize display;
@synthesize intermediate;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setDisplay:nil];
[self setIntermediate:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)number:(id)sender {
NSString *button_pressed = [[sender titleLabel] text];
NSString *current_value = [display text];
NSString *new_value;
if([current_value isEqualToString:@"0"])
{
new_value = button_pressed;
}
else
{
new_value = [current_value stringByAppendingString:button_pressed];
}
[display setText:new_value];
}
- (IBAction)mul:(id)sender {
}
- (IBAction)add:(id)sender {
NSString *val1 = [display text];
NSString *val2 = [intermediate text];
float f1 = [val1 floatValue];
float f2 = [val2 floatValue];
float answer = f1 + f2;
NSString *final = [NSString stringWithFormat:@"%.02f", answer];
[display setText:final];
[intermediate setText:@""];
}
- (IBAction)sub:(id)sender {
}
- (IBAction)div:(id)sender {
}
- (IBAction)clear:(id)sender {
[display setText:@"0"];
[intermediate setText:@""];
}
- (IBAction)compute:(id)sender {
}
- (IBAction)push:(id)sender {
[intermediate setText:[display text]];
[display setText:@"0"];
}
- (IBAction)pie:(id)sender {
NSNumber *n1 = [NSNumber numberWithDouble:M_PI];
[display setText:[n1 stringValue]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment