#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a, b, c, ex, bac, sum1, sr, sum2, prod, quo;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1);
cout << "Using the Quadratic Formula.\n"
<< "-----------------------------------\n"
<< "Please enter the value of a: ";
cin >> a;
cout << "Please enter the value of b: ";
cin >> b;
cout << "Please enter the value of c: ";
cin >> c;
ex = pow(b,2);
cout << "-----------------------------------\n"
<< "Evaluate the power of b,\n"
<< b << " ^ 2 = " << ex << endl;
bac = -4 * a * c;
cout << "Calculate the product of -4(a)(c), \n"
<< "-4(a)(c) = -4(" << a << ")("
<< c << ") = " << bac << endl;
sum1 = ex + bac;
cout << "Add the product of b and -4(a)(c), \n"
<< ex << " + " << bac << " = " << sum1 << endl;
sr = sqrt(sum1);
cout << "Evaluate the square root of " << sum1 << "," <<endl
<< "√" << sum1 << " = " << sr << endl;
if (sr > 0) {
sum2 = -b + sr;
cout << "Calculate the sum of -" << b << " and " << sr << "," << endl
<< "-" << b << " + " << sr << " = " << sum2 << endl;
prod = 2 * a;
cout << "Multiply for the product of 2 and (a), \n"
<< "2(" << a << ") = " << prod << endl;
quo = sum2 / prod;
cout << "Calculate the quotient of " << sum2 << " and "<< prod << "," << endl
<< sum2 << " / " << prod << " = " << quo << endl
<< "-----------------------------------\n"
<< "x = " << quo << endl
<< "-----------------------------------\n";
}
else {
cout << "-----------------------------------\n"
<< " - Undefined -" << endl
<< "The square root of a negative number does not exist" << endl
<< "in the set of real numbers." << endl
<< "-----------------------------------\n";
}
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter