# A problem in the middle of ... !

• 02-27-2011
Coca cola
A problem in the middle of ... !
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; }```
• 02-27-2011
Salem
Can you copy/paste your console session, showing what you type in and what gets printed?
• 02-27-2011
C_ntua
Code:

`(-b-sqrt(d))/(2*a)`
• 02-27-2011
Coca cola
Thank you very, very much for your answer ! A small detail, that i didn't notice at all !