Like "bluecoder" has pointed out already, you should check to see if
a == 0,
before computing
root_positif and
root_negatif. 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 and
root_negatif with the
sqrt function, you'll get an error. You'll have to deal with it if it is negative.
Another suggestion:
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
cout<<"The differential is "<<endl;
cout<<differential<<endl;
if(differential==0)
{
cout<<"The equation are single root."<<endl;
}
else if(differential<0)
{
cout<<"The equation are two complex root."<<endl;
}
else
{
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
http://www.akiti.ca/Quad2Deg.html
Hope this helps.