#include "D:\c++_book\std_lib_facilities.h"
using namespace std;
struct Solve {
int numRoots;
double x1;
double x2;
};
Solve sqeq(double a, double b, double c) {
Solve equation;
double d = b * b - 4 * a * c, x1, x2;
try {
if (d > 0) {
x1 = ((-b) + sqrt(d)) / (2 * a);
x2 = ((-b) - sqrt(d)) / (2 * a);
equation.numRoots = 2;
equation.x1 = x1;
equation.x2 = x2;
return equation;
}
if (d == 0) {
x1 = -(b / (2 * a));
x2 = x1;
equation.numRoots = 1;
equation.x1 = x1;
equation.x2 = x2;
return equation;
}
if (d < 0) {
equation.numRoots = 0;
equation.x1 = 0;
equation.x2 = 0;
error("Equation has no roots!");
return equation;
}
}
catch (exception& e) {
cerr << "Oopsie... " << e.what() << endl;
}
}
int main() {
double a, b, c;
cin >> a >> b >> c;
Solve equation = sqeq(a, b, c);
if (equation.numRoots == 1)
cout << "Root is: " << equation.x1;
if (equation.numRoots == 2)
cout << "Roots is: " << equation.x1 << " " << equation.x2;
}
>