Hi everyone, I was solving a problem about analysing solutions of quadratic equation, and of corse calculating the solutions. But when I enter the coefficients of equation 2,4,2 ,actually always when first one is bigger than one the results are incorrect. Here is the code:

Code:#include<iostream> #include<cmath> using namespace std; int main(){ double a,b,c; cout<<"Enter a : "; cin>>a; cin.ignore(1000,'\n'); cout<<"Enter b: "; cin>>b; cin.ignore(1000,'\n'); cout<<"Enter c : "; cin>>c; double d=b*b-4*a*c; if(d>=0){ double x1=((-b+sqrt(d))/2*a); double x2=((-b-sqrt(d))/2*a); cout<<"x1="<<x1<<" "<<"x2="<<x2<<endl; } else{ d=-d; double re=-b/2*a; double im=sqrt(d)/2*a; cout<<"x1="<<"("<<re<<","<<im<<")"<<" "<<"x2="<<"("<<re<<","<<-im<<")"<<endl; } return 0; }