I am writing a program that will output the roots of a 2nd degree polynomial. I have to use the function find_roots, I know i am using it wrong but i am lost as to how i would call it twice for both roots. I think i could use 'static' to return two values, but not sure how. Any help would be appreciated.
Also, i wrote a similar program before and this is it, would this still work if i just put it into my find_root function? If i tweaked it a bit to return the roots to main0 and cout them there?
double A;
double B;
double C;
double x1;
double x2;
double disc;
cout<<"This program will calculate the roots of a 2nd order polynomial, Ax^2 + Bx + C\n\n";
cout<<"Please input the values for the coefficients of the polynomial (A, B, C) ";
cin>>A>>B>>C;
x1 = (-B + sqrt(B*B - 4*A*C))/(2*A);
x2 = (-B - sqrt(B*B - 4*A*C))/(2*A);
disc = (B*B - 4*A*C); //discriminant
if ( disc < 0 )
cout<<"\nThe roots are "<<setw(7)<<fixed<<setprecision(2)<<(-B/2*A)<< " +/-" <<setw(7)<<(sqrt(abs(disc))/2*A)<<"i "; //imaginary
else
{
if(A==0)
{
cout<<"That equation describes a line since A = 0"<<endl; // line
}
else
{cout<<fixed<<setprecision(2)<<"The roots of the polynomial are x1 = "<<setw(6)<<fixed<<setprecision(2)<<x1<<" and x2 = "<<setw(6)<<x2<<endl;
}
}
system("Pause");
return 0;