0

Still learning in objective c and have a problem I'm just not able to figure out. I'm trying to write an app to figure angles and I've got 4 textfields, 2 sides and 2 angles. The user can either enter the 2 side dimensions and app will figure the angles or user can enter 1 side and an angle and the app will figure the other side and angle. In this my process of figuring out how to get this done I did this code:

- (IBAction)calcPressed {
    float a = ([sideA.text floatValue]/[sideB.text floatValue]);
    float b = atan(a)*180/3.141592653589;
    float e = 90 - b;
    angleA.text = [[NSString alloc] initWithFormat:@"%f", b];
    angleB.text = [[NSString alloc] initWithFormat:@"%f", e];

to take the 2 sides entered and figure the angles and it works fine. So now I need to figure out how to allow either 2 sides to be entered or 1 side and 1 angle so I've come up with this:

- (IBAction)calcPressed {
    float a = ([sideA.text floatValue]);
    float b = ([sideB.text floatValue]);
    float c = ([angleA.text floatValue]);
    float d = ([angleB.text floatValue]);

    if(angleA.text, angleB.text = @"") {
        float e = a/b;

        float f = atan(e)*180/3.141592653589;
        float g = 90 - f;
        angleA.text = [[NSString alloc] initWithFormat:@"%f", f];
        angleB.text = [[NSString alloc] initWithFormat:@"%f", g];
    } else if (sideB.text, angleB.text = @"") {
        float e = tan(c);
        b = a/e;
        d = 90 - c;
        sideB.text = [[NSString alloc] initWithFormat:@"%f", b];
        angleB.text = [[NSString alloc] initWithFormat:@"%f", d];
    }
}

The first part works fine but the second part doesn't. Like I said I'm pretty new at this and I'm sure there is a better way of doing things, like there's probably a better way to divide by pi but that part I could get to work. Any pointers would be greatly appreciated.

Abizern
  • 146,289
  • 39
  • 203
  • 257
mmoore410
  • 417
  • 1
  • 5
  • 12

1 Answers1

1

Change this

if(angleA.text, angleB.text = @"") {

to

if ([angleA.text isEqualToString: @""] && [angleB.text isEqualToString: @""]) {

and same to the else if part.

dasdom
  • 13,975
  • 2
  • 47
  • 58
  • Thank You so much! I knew it had to be something fairly simple. Yes I will work on checking for 0 as well but trying to take it in steps, get 1 thing working and understand it before I move to the next. – mmoore410 Nov 16 '11 at 17:21
  • If this solved your problem you may accept this answer as the correct answer. – dasdom Nov 16 '11 at 17:56