This is my code for the quadratic equation. It keeps telling me that my else is illegal since no matching if statement and my else statement is missing a statement

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273`` ``````#include #include #include #include using namespace std; int main() { string Name; double a; double b; double c; double discriminant; double x1; double x2; cout << scientific; bool bFail; cout << "\t\t\t===============================\n"; cout << "\t\t\t\tQuadratic Equation\n"; cout << "\t\t\t===============================\n"; cout << "Full Name:"; getline(cin,Name); cout << "\n\n"; cout << setw(25) << Name << "\n"; cout << "This program will provide solutions for an equation of the form:\n"; cout << "\t\ta*x^2 + b*x + c = 0\n"; cout << "Where a,b, and c are integers and a is not equal to zero\n"; do{ cout << "Enter value of a:"; cin >> a; if ( a = 0); { cout << "No solution!\n"; } else if ( a != 0) { bFail = cin.fail(); cin.clear(); cin.ignore(numeric_limits::max(),'\n'); } }while(bFail == true); do{ cout << "Enter value of b:"; cin >> b; bFail = cin.fail(); cin.clear(); cin.ignore(numeric_limits::max(),'\n'); }while(bFail == true); do{ cout << "Enter value of c:"; cin >> c; bFail = cin.fail(); cin.clear(); cin.ignore(numeric_limits::max(),'\n'); }while(bFail == true); discriminant = pow(b,2) - 4 * a * c; return 0; }``````
`if ( a = 0); // <--- Remove the semicolon - use == operator `
Last edited on
thank you so much! but now the problem is that it says that bFail is being ran without being initialized and the programming keeps running. how can i avoid this?
Exactly as it says ;)

You declared your Boolean bFail and have it tested in your do-while loop, but you never set it to true or false before hand.
Topic archived. No new replies allowed.