/*
   Solve 2nd degree equation.
*/

#include <iostream>   // cin,cout
#include <cmath>      // sqrt
using namespace std;


void Quadratic_solver(double a, double b, double c, int& solutions, double& r1, double& r2)
/*


*/
{
    // First we find the discriminant:
    double D=b*b-4.0*a*c;

    if (fabs(D)<1e-8)
    {  // D==0 so a douple root
        solutions=1;
        r1 = r2 = -b/(2.0*a);
    }
    else if (D<0)
    {  // No real solutions
        solutions=0;
    }
    else
    {
        // Two real solutions
        solutions=2;
        r1=(-b+sqrt(D))/(2.0*a);
        r2=(-b-sqrt(D))/(2.0*a);
    }
}

int main()
{
      double a=2.0, b=4.0, c=4.0;   // No roots
//    double a=1.0, b=4.0, c=4.0;   // Single root
//    double a=1.0, b=6.0, c=2.0;   // two roots

    // Variables to transfer as references so function can
    // set their values.
    int nsol;
    double root1,root2;

    //                _input_    ____output_______
    Quadratic_solver( a, b, c,  nsol, root1, root2);

    cout << "Solutions: " << nsol;
    if (nsol==1) cout << " double root at "<< root1;
    if (nsol==2) cout << " Two roots "<< root1 << "  and  " << root2;
    cout << endl;
    return 0;
}

