Ok, so I am a bit new with the iPhone SDK and this is getting frustrating. I am trying to build an application where the user types in the values of a,b, and c for a quadratic equation and it gives them x. so far, this is what I have
HTML Code:
- (IBAction) solve {
//a is the string, afield is the text field, ia is double
a = afield.text;
ia = [a doubleValue];
b = bfield.text;
ib = [b doubleValue];
c = cfield.text;
ic = [c doubleValue];
ix1 = (-ib + sqrt((ib*ib)-4*(ia*ic)))/2*ia;
x1 = [NSString stringWithFormat:@"%i", ix1];
x1field.text = x1;
ix2 = (-ib - sqrt((ib*ib)-4*(ia*ic)))/2*ia;
x2 = [NSString stringWithFormat:@"%i", ix2];
x2field.text = x2;
x2field.text = [NSString stringWithFormat:@"%d", ix2];
root = ((ib*ib)-4*(ia*ic))/2*ia;
if (root == 0) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Oh No!" message:@"There is no real answer to this equasion." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}
I don't get any errors, but the x1field and x2field values are always 0. I'm pretty sure the answer is something simple. Help would be greatly appreciated