I’m getting this error when I’m trying to calculate the slope between two points. The user has inputted the points into text fields defined as X1,Y1,X2,Y2. Then they hit the button ‘calculate’.
Here’s my code where I’m getting the error
-- (IBAction)calculate:(id)sender {
self.slopeCalculate = (self.Y2.text - self.Y1.text)/(self.X2.text - self.X1.text);
}
It’s specifically only pointing to ‘self.X2.text’ so I don’t know what’s going on. What am I doing wrong here?
You can’t do numeric calculation on text data like
NSString, you need to turn them into numerics first, such as with:You also need to watch out for the edge case of vertical lines since these have an infinite (or undefined) slope (
x2Dbl - x1Dblwill be zero).