-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.m
52 lines (33 loc) · 1.64 KB
/
Controller.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// TipCalculator.m
// TipperAssignment
//
// Created by David Pullar on 3/2/2014.
// Copyright (c) 2014 David Pullar. All rights reserved.
//
#import "Controller.h"
@implementation Controller
double amount = 0;
- (IBAction)calculateTip:(UITextField*)sender {
NSLog(@"test");
amount = [[billTotalField text] doubleValue];
double tenPerc = (10 * amount) / 100;
double fifteenPerc = (15 * amount) / 100;
double twentyPerc = (20 * amount) / 100;
double tenTotal = amount + tenPerc;
double fifteenTotal = amount + fifteenPerc;
double twentyTotal = amount + twentyPerc;
[tipTenPercentField setText:[NSString stringWithFormat:@"%.2f", tenPerc]];
[tipFifteenPercentField setText:[NSString stringWithFormat:@"%.2f", fifteenPerc]];
[tipTwentyPercentField setText:[NSString stringWithFormat:@"%.2f", twentyPerc]];
[totalTenField setText:[NSString stringWithFormat:@"%.2f", tenTotal]];
[totalFifteenField setText:[NSString stringWithFormat:@"%.2f", fifteenTotal]];
[totalTwentyField setText:[NSString stringWithFormat:@"%.2f", twentyTotal]];
}
- (IBAction)updateCustom:(UISlider*)sender {
double customPerc = [sender value];
[customPercentLabel setText:[NSString stringWithFormat:@"%.2f%%", customPerc]];
[tipCustomPercentField setText:[NSString stringWithFormat:@"%.2f", (customPerc * amount) / 100]];
[totalCustomField setText:[NSString stringWithFormat:@"%.2f", amount + ((customPerc * amount) / 100)]];
}
@end