// G. Hagopian -- Exercise 18 of PPP4

/*
18. Write a program to solve quadratic equations. A quadratic equation is 
of the form ax2 + bx + c = 0
If you don’t know the quadratic formula for solving such an expression, do 
some research. Remember, researching how to solve a problem is often 
necessary before a programmer can teach the computer how to solve it. 
Use doubles for the user inputs for a, b, and c. Since there
are two solutions to a quadratic equation, output both x1 and x2.
*/

#include <iostream>
using namespace std;

int main() {
	double a{}, b{}, c{}, x1{}, x2{}, x1real{}, x1imag{}, x2real{}, x2imag{};
	cout << "Enter the coefficients a!=0, b, and c for ax^2+bx+c == 0: ";
	cin >> a >> b >> c;
	double disc = b * b - 4 * a * c;
	if (disc >= 0) {
		cout << "The solutions are " << (-b + sqrt(disc)) / (2 * a)
			<< " and " << (-b - sqrt(disc)) / (2 * a);
	}
	else {
		double complexPart = sqrt(-disc) / (2 * a);
		cout << "The solutions are " << -b / (2 * a) << " + " << complexPart << " * i\n and "
			<< -b/(2*a) << " - " << complexPart << " * i.";
	}

}