#include<iostream>
#include<cmath>
#include<math.h>
#include <iomanip>
usingnamespace std;
void solve()
{
double a,b,c; // coefficients
cout << "Please enter three floating-point numbers (a b c) to be used as the coefficients in a*x*x + b*x + c == 0: ";
while (cin>>a>>b>>c) {
if(a==0) { // just b*x+c==0
// easy: x == -c/b
if (b==0) // easy: c == 0
cout << "no root (since x isn't used)\n";
else
cout << "x == " << -c/b << '\n';
}
elseif (b==0) { // a*x*x+c==0
// we know that a is not zero so, x*x == -c/a
// if -c/a 0, obviousl x is zero
// if -c/a is positive, there are two real solutions
// if -c/a is negative, there are not real solutions
double ca = -c/a;
if (ca == 0)
cout << "x==0\n";
elseif (ca < 0)
cout << "no real roots\n";
else
cout << "two real roots: " << sqrt(ca) << " and " << -sqrt(ca) << '\n';
}
else { // here we finally have to apply the complete formula
// we know that neither a nor b is zero
double sq = b*b-4*a*c;
if (sq==0)
cout << "one real root: " << -b/(2*a) << '\n';
elseif (sq<0)
cout << "no real roots\n";
else
cout << "two real roots: " << setprecision(12) << (-b+sqrt(sq))/(2*a) << " and " << (-b-sqrt(sq))/(2*a) << '\n';
}
cout << "please try again (enter a b c): ";
}
}
int main()
{
void solve();
}