为什么是错的求解答刚刚学

#include
#include
#include
using namespace std;
int main()
{
double a=1, b=1, c=1, d=1;
cout << "Enter a,b,c:";
d = b * b - 4 * a * c;
cin >> a >> b >> c;
if (0==a) {if(0==b)cout<<"方程不成立\n";
else cout<< "x =" << fixed << setprecision(2) << -c / b << endl;}
else if (d >= 0) {
cout << "x1 =" << fixed << setprecision(2) << (-b + sqrt(d)) / (2 * a) << endl;
cout << "x2 =" << fixed << setprecision(2) << (-b - sqrt(d)) / (2 * a) << endl;
}
else {
cout << "x1 =" << fixed << setprecision(2) << -b / (2 * a) << " + " << sqrt(-d) / (2 * a) << "i" << endl;
cout << "x2 =" << fixed << setprecision(2) << -b / (2 * a) << " - " << sqrt(-d) / (2 * a) << "i" << endl;
}
return 0;
}

修改如下,供参考:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    double a=1, b=1, c=1, d=1;
    cout << "Enter a,b,c:";
    cin >> a >> b >> c;    //修改
    d = b * b - 4 * a * c; //修改
    if (0 == a) {
        if(0 == b)
            cout<<"方程不成立\n";
        else
            cout<< "x =" << fixed << setprecision(2) << -c / b << endl;
    }
    else if (d >= 0) {
        cout << "x1 =" << fixed << setprecision(2) << (-b + sqrt(d)) / (2 * a) << endl;
        cout << "x2 =" << fixed << setprecision(2) << (-b - sqrt(d)) / (2 * a) << endl;
    }
    else {
        cout << "x1 =" << fixed << setprecision(2) << -b / (2 * a) << " + " << sqrt(-d) / (2 * a) << "i" << endl;
        cout << "x2 =" << fixed << setprecision(2) << -b / (2 * a) << " - " << sqrt(-d) / (2 * a) << "i" << endl;
    }
    return 0;
}