/*
  Defining functions. see Nyhoff P155-159

  Mixing call-by reference and call-by-value to return multiple results.

*/


#include <iostream>
#include <cmath>
using namespace std;

int SolveQuadraticEquation(double a,double b,double c,   double& r1, double& r2)
/*
   Returns number of solutions, solutions returned via call-by-reference semantics using r1,r2
   Quadratic equation specified call-by-value semantics via a,b,c.
*/
{
// Set default return values:
   r1=-0;
   r2=-0;

// Discriminant
   double D=b*b-4.0*a*c;

// No solutions:    
   if (D<0) return 0;
    
// One solution:
   if (D==0)
      {
         r1 = r2 = -b/(2.0*a);
         return 1;
      }
    
// Two solutions;
   r1 = (-b+sqrt(D))/(2.0*a);
   r2 = (-b-sqrt(D))/(2.0*a);
    
   return 2;
}


int main()
{
   double a=5.5, b=1.0, c=2.0;
   double r1,r2;
   
   cout << "Return value=" << SolveQuadraticEquation(a,b,c) << endl;
   cout << "r1 = " << r1 << endl;   
   cout << "r2 = " << r2 << endl;   

   return 0;
}
