-1

i need help with this.

-(IBAction) equalsPressed:(id)sender{



if(((IBAction) dividePressed) = YES){
    int equals = labelsNumber.text.intValue;
    labelsNumber.text = @"";
    int ans = divide / equals;
    NSString *answer = [NSString stringWithFormat:@"%d", ans];
    labelsNumber.text = answer;

i am building a calculator and the error is "Expected Expression."

Please Help

  • What is `dividePressed`? Is that a method? An instance variable? – rmaddy Feb 27 '13 at 01:45
  • In addition to the excellent answers below, I recommend [this SO thread](http://stackoverflow.com/q/1643007/620197) to get a better understanding of what an `IBAction` is. – Mike D Feb 27 '13 at 01:52

2 Answers2

1

I assume you are trying to determine whether or not dividePressed has been called yet. You could do something like this:

BOOL dividePressed;

-(IBAction) dividePressed:(id)sender{
  dividePressed = YES;
}

-(IBAction) equalsPressed:(id)sender{
  if(dividePressed) {

  }
}
user941868
  • 36
  • 2
0

I think you're doing it backwards. In the equalsPressed method you'd do the calculation. In the dividePressed you'd store the operator:

-(IBAction) equalPressed:(id)sender {
int equals = labelsNumber.text.intValue;
    int ans;
    labelsNumber.text = @"";
    switch(operator) {
    case DIVIDE:
    ans = op1 / op2;
    break;
    }
    NSString *answer = [NSString stringWithFormat:@"%d", ans];
    labelsNumber.text = answer;
}

-(IBAction) dividePressed:(id)sender {
  operator = DIVIDE;
}

I'd do the same thing with the operands (op1, op2), store them and operate on them in the equals method

Richard Brown
  • 11,219
  • 4
  • 32
  • 42