// Example Program: quad.cpp // Solving the Quadratic Equation #include #include main() { float a; float b; float c; float temp; float x1; float x2; cout << "Welcome to the Quadratic Equation Solver!\n\n"; cout << "\n\n\nEnter coeficient of X-squared term: "; cin >> a; cout << "\n\n\nEcho check on data: a = " << a << endl; cout << "\n\n\nEnter coeficient of X term: "; cin >> b; cout << "\n\n\nEcho check on data: b = " << b << endl; cout << "\n\n\nEnter constant coeficient term: "; cin >> c; cout << "\n\n\nEcho check on data: b = " << c << endl; temp = b*b - 4*a*c; if ( temp == 0 ) { x1 = -b/(2*a); x2 = -b/(2*a); cout << "\n\n\n\nRoots are real and equal!\n\n"; cout << "\tX1 = " << x1 << ", X2 = " << x2 << endl; } else { if ( temp > 0 ) { x1 = ( -b + sqrt(temp) )/( 2*a ); x2 = ( -b - sqrt(temp) )/( 2*a ); cout << "\n\n\n\nRoots are real and unequal!\n\n"; cout << "\tX1 = " << x1 << ", X2 = " << x2 << endl; } else { if ( temp < 0 ) { x1 = -b/(2*a); x2 = -b/(2*a); cout << "\n\n\n\nRoots are Complex!\n\n"; cout << "\tX1 = " << x1 << " + j" << sqrt(-temp) << ", X2 = " << x2 << " - j" << sqrt(-temp) << endl; } } } return 0; }