Answer the question
In order to leave comments, you need to log in
Objective-c calculator?
I am writing a calculator on an iPhone (objective - c), I ran into such a problem:
Example: 2+2=4, after I want to enter a number, but it adds this number to the end of the line (I found the case 4xxx, where x is the input numbers), not as a new value.
How can it be implemented?
// Так вставляю цифры(0-9)
-(void)setNumber:(int)num{
if(!isDecimal){
displayNumber *= 10;
displayNumber += num;
mainLabel.text = [NSString stringWithFormat:@"%g",displayNumber];
}
else{
mainLabel.text = [mainLabel.text stringByAppendingString:[NSString stringWithFormat:@"%d", num]];
}
displayNumber = [mainLabel.text doubleValue];
}
// При нажатие баттона, цифра добавляется в лабел
- (IBAction)num1:(id)sender {
[self setNumber:1];
}
// При нажатие на баттон равно
- (IBAction)equals:(id)sender{
[self operations:operation];
mainLabel.text = [NSString stringWithFormat:@"%g",resultNumber];
displayNumber = [mainLabel.text doubleValue];
resultNumber = 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question