Like "bluecoder" has pointed out already, you should check to see if a
== 0, before
. The program may compile okay, but if you execute it, and a
== 0, you will get a "divide by zero" error.
I also suggest that you check to see if differential
>= 0 right after it is computed
If it is negative, when you compute root_positif
with the sqrt
function, you'll get an error. You'll have to deal with it if it is negative.
instead of repeating the two lines outputting differential
, take them out of the if
conditions. That way you are not repeating those two lines three times:
cout<<"The differential is "<<endl;
cout<<"The equation are single root."<<endl;
cout<<"The equation are two complex root."<<endl;
cout<<"The equation are two real root."<<endl;
It wouldn't be too hard to make the program handle complex results too. Will you be adding this capability in the future?
FYI: there are many quadratic equation solvers available online, if you would like to check the results of your program against the results of another program, for example,
Quadratic Equation Solver
Hope this helps.