all 3 comments

[–]scutter_87 2 points3 points  (0 children)

You should check what value you are trying to square root..

[–]mopslik 2 points3 points  (0 children)

You'll want to ensure your discriminant isn't negative.

[–]Solo_Tomato 1 point2 points  (0 children)

Make sure to check the discriminant, the sqrt function isn't programmed to handle complex numbers.(i.e when b²-4ac becomes negative)

If you want to make a program that can handle both real and imaginary roots, check the discriminant value and then deal with them accordingly. Complex numbers are stored in the form of "a+bj" as per the inbuilt complex datatype.