// quadrati.C
// Name: Gary T. Leavens
// TA: Bjarne Stroustrup
// Section: A1

#include <iostream.h>
#include <math.h>
#include "prompt.h"
#include "ask_yn.h"

int main()
  // MODIFIES: cin, cout
  // POST: cout has prompts for a, b, and c written to it,
  // and after each prompt, the corresponding double is read from cin;
  // finally cout has the two roots printed.
{
  double a, b, c;
  int ret_code;

  do {
    // read in a, b, and c
    prompt("a? ");
    cin >> a;
    prompt("b? ");
    cin >> b;
    prompt("c? ");
    cin >> c;
    
    double discriminant = b*b - 4*a*c;
    double a_twice = 2*a;
    double minus_b = -b;
    
    if (discriminant > 0.0) {
      double sqrt_d = sqrt(discriminant);
      cout << "The positive root is: ";
      cout << (minus_b + sqrt_d)/(a_twice) << endl;
      cout << "The negative root is: ";
      cout << (minus_b - sqrt_d)/(a_twice) << endl;
      ret_code = 0;
    } else if (discriminant == 0.0) {
      cout << "roots same" << endl;
      continue;
    } else {
      cerr << "the discriminant is negative" << endl;
      ret_code = 1;
      break;
    }
    cout << "end of it" << endl;
  } while (ask_yn("another one (y/n)? "));
  return ret_code;
}

