I've heard that there is an assignment in school that says you have to write a code for the quadratic equation. I decided to try my hand at it. The equation seems to be losing decimals some where in the equation.
int main ()
{
double j,a,b,c,d,e,f,g,h;
cout << "Enter a";
cin >> a;
cout << "Enter b";
cin >> b;
cout << "Enter c";
cin >> c;
system("PAUSE");
d = b-2*b;
e =(b*b)-(4*a*c);
f = sqrt(e);
g = f + d;
h = g/(2*a);
cout.precision(5);
if
(h < 0)
{cout << "If you add, x = -" << h <<endl;
system("PAUSE");
f = sqrt(e);
g = f - d;
h = g/(2*a);
cout << "If you subtract, x = -" << h << endl;
system("PAUSE");
return 0; }
if
(h >= 0)
{cout << fixed << "If you add, x = " << h <<endl;
system("PAUSE");
f = sqrt(e);
g = f - d;
h = g/(2*a);
cout << "If you subtract, x = " << h << endl;
system("PAUSE");
return 0; }
}
but for some reason, the program itself is only dealing in positives.