Mar 29, 2013 at 12:25am UTC
This isn't doing what you think it's doing. You've defined your function to return a double. What this is doing is returning the result of the expression , so it's returning the value of
Mar 29, 2013 at 12:28am UTC
Oh, yeah I noticed that but even if I just do
it still says: "NaN". I don't get why. The code looks good to me.
Mar 29, 2013 at 2:03am UTC
pow(-1, 2) = 1 > 0
1 * -4 = -4 < 0
10 * 1 = 10 > 0
-4 * 10. = -40 < 0
sqrt( -40 ) ...... Complex
Mar 29, 2013 at 2:07am UTC
Is there a way to handle complex numbers in C++?
Mar 29, 2013 at 4:23pm UTC
Thanks, that fixed the problem.
Mar 29, 2013 at 4:39pm UTC
I just saw this discussion. Cubbi's solution fixed the problem partly because it uses the correct equation. Your original equation contained
sqrt(b 2 * (-4ac)
but it should have contained
sqrt(b 2 - 4ac)
Also, the total should have been divided by 2a, not 2.
Cubbi's solution corrected both of those.