Put that in code tags and indent it first.
I'm going to look at your problem from a more theoretical view because I understand what you are doing. Here's the steps I would propose you undertake:
Get the three coefficients a, b and c.
Check a - if a is zero, either force them to input a again, or say that the equation is not quadratic. (Because of course, a=0 would make it a linear equation.)
1 2 3 4 5
|
while (a == 0)
{
cout << "NOT QUADRATIC! Input that again please.";
cin >> a;
}
|
Second check - examine the discriminant. Mathematically speaking, if the discriminant is less than zero there are no real roots. (If you have forgotten your quadratics, the discriminant is (b^2) - 4ac)
1 2 3 4
|
if (((b*b)-(4*a*c)) < 0)
{
cout << "Sorry, there are no real roots.";
}
|
If the discriminant is not negative, check if it is zero. If so, adjust your equation accordingly because there is only one root.
Finally - if the discriminant is neither zero nor negative, it must be positive so calculate the two roots accordingly and display them.
EDIT: By the way, I do see your actual problem. You have only one equals sign in your else and you need to say else if, not just else. Review your logical operators and if/else if tree. I don't really see the point of finding a line's x-intercept in a quadratic root finder but that's beside the point.