#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" << "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); bac = -4 * a * c; sum1 = ex + bac; sr = sqrt(sum1); if (sr > 0) { sum2 = -b + sr; prod = 2 * a; quo = sum2 / prod; cout << "x = " << quo << endl; } else { cout << " - Undefined -" << endl << "The square root of a negative number does not exist" << endl << "in the set of real numbers." << endl; } 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