Quadratic

I was able to get this working at one point but now I don't know whats wrong with it. It will compile but it gives an -1.#nd(or something close) as an answer for x1 and x2. Help please.

//call quadratic formula
a = nums[0];
b = nums[1];
c = nums[2];
x1 = ((-b) + (sqrt((pow(b, 2) - (4 * a * c)))))/(2 * a);
x2 = ((-b) - (sqrt((pow(b, 2) - (4 * a * c)))))/(2 * a);
What are the values of a b c ?
float and I made x1 and x2 double, but tried them as float and they still don't work.
the actual values that I am testing with are just 1, 2, 3.(a, b, c).
pow(b, 2) - (4 * a * c) with 1 2 3 is negative. If you want to get a root of a negative, use complex numbers. Otherwise, check this value before calculating roots.
I got it. Thanks.
Topic archived. No new replies allowed.