#include #include using namespace std; int main() { cout << "This program solves quadratic equations." << endl; double a, b, c, d, x1, x2; //Initializes variables double e; //This is for the complex calculation cout <<"a: "; //Asks for variables cin >> a; cin.ignore(); cout <<"b: "; cin >> b; cin.ignore(); cout <<"c: "; cin >> c; cin.ignore(); d = pow(b,2) - 4*a*c; //Calculates what is under the square root e = sqrt(fabs(d)); //For complex calculation if (d < 0) if (b > 0) {cout << "The equation has two complex solutions." << endl; cout << "X1 = " << b/(2*a) <<" + " << e/(2*a) << "i" << endl; cout << "X1 = " << b/(2*a) <<" - " << e/(2*a) << "i" << endl; cin.get(); return(0);} else {cout << "The equation has two complex solutions." << endl; cout << "X1 = " << e/(2*a) << "i" << endl; cout << "X1 = " << -e/(2*a) << "i" << endl; cin.get(); return(0);} else if (a == 0) {cout<< "That is not a quadratic equation." << endl; cin.get(); return(0);} else if (d == 0) {cout<<"The equation has one solution." << endl; x1 = ((-b)+sqrt(d))/(2*a); cout<<"X: " << x1 << endl; cin.get(); return(0);} else {cout<<"The equation has two solutions." << endl; x1 = ((-b)+sqrt(d))/(2*a); x2 = ((-b)-sqrt(d))/(2*a); cout<<"X1: " << x1 << endl; cout<<"X2: " << x2 << endl; cin.get(); return(0);} }