Permalink
Browse files

fixed a bug with backspace and decimal points, now users can enter de…

…cimal points after they backspace to remove one
  • Loading branch information...
1 parent 236d401 commit 963452788ffd0a9e20a6e4ddc005eca4df5ef3c6 @johndbritton committed Mar 18, 2012
Showing with 3 additions and 7 deletions.
  1. +3 −7 calculator/calculator/CalculatorViewController.m
@@ -11,7 +11,6 @@
@interface CalculatorViewController()
@property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
-@property (nonatomic) BOOL userIsEnteringDigitsAfterDecimalPoint;
@property (nonatomic, strong) CalculatorBrain *brain;
@end
@@ -20,7 +19,6 @@ @implementation CalculatorViewController
@synthesize display = _display;
@synthesize programDisplay = _programDisplay;
@synthesize userIsInTheMiddleOfEnteringANumber = _userIsInTheMiddleOfEnteringANumber;
-@synthesize userIsEnteringDigitsAfterDecimalPoint = _userIsEnteringDigitsAfterDecimalPoint;
@synthesize brain = _brain;
- (CalculatorBrain *)brain {
@@ -38,26 +36,24 @@ - (IBAction)digitPressed:(UIButton *)sender {
}
- (IBAction)decimalPointPressed:(id)sender {
- if(!self.userIsEnteringDigitsAfterDecimalPoint){
+ NSRange rangeOfDecimalPoint = [self.display.text rangeOfString:@"."];
+ if (rangeOfDecimalPoint.location == NSNotFound) {
[self digitPressed:sender];
- self.userIsEnteringDigitsAfterDecimalPoint = YES;
- self.userIsInTheMiddleOfEnteringANumber = YES;
+ self.userIsInTheMiddleOfEnteringANumber = YES;
}
}
- (IBAction)enterPressed {
[self.brain pushOperand:[self.display.text doubleValue]];
self.programDisplay.text = [self.programDisplay.text stringByAppendingString:[NSString stringWithFormat:@"%@ ", self.display.text]];
self.userIsInTheMiddleOfEnteringANumber = NO;
- self.userIsEnteringDigitsAfterDecimalPoint = NO;
}
- (IBAction)clearPressed {
[self.brain clear];
self.display.text = @"0";
self.programDisplay.text = @"";
self.userIsInTheMiddleOfEnteringANumber = NO;
- self.userIsEnteringDigitsAfterDecimalPoint = NO;
}
- (IBAction)backspacePressed {

0 comments on commit 9634527

Please sign in to comment.