1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
if (algselection==4)
{
cout << "\n+----Quadratic Equation Solution----+\n"
<< "| Enter the Coefficient on x^2 |\n"
<< " ";
double avalue, bvalue, cvalue, b2, ac4, b2ac4, b2ac4topos, bover2a, b2ac4over2a, negbplus, negbminus, sqrb2ac4, twoa, plusover2a, minusover2a;
cin >> avalue;
cout << "| Enter the Coefficient on x |\n"
<< " ";
cin >> bvalue;
cout << "| Enter the Third Term |\n"
<< " ";
cin >> cvalue;
ac4 = avalue * cvalue * 4;
b2 = pow(bvalue, 2);
b2ac4 = b2 - ac4;
if(b2ac4 >= 0)
{
sqrb2ac4 = sqrt(b2ac4);
negbplus = -bvalue + sqrb2ac4;
negbminus = -bvalue - sqrb2ac4;
twoa = 2 * avalue;
plusover2a = negbplus / twoa;
minusover2a = negbminus / twoa;
cout << "| The Values of X are |\n"
<< " " << setprecision(4) << plusover2a
<< "\n " << setprecision(4) << minusover2a
<< "\n+-----------------------------------+" << endl;
}
if(b2ac4 < 0)
{
b2ac4topos = b2ac4 * -1;
sqrb2ac4 = sqrt(b2ac4topos);
twoa = 2 * avalue;
bover2a = -bvalue / twoa;
b2ac4over2a = sqrb2ac4 / twoa;
cout << "| The Values of X are |\n " << setprecision(4) << bover2a
<< " +/- " << setprecision(4) << b2ac4over2a << "i\n"
<< "+-----------------------------------+" << endl;
}
|