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 43 44 45 46
|
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
bool quadratic(int, int, int, double, double);
int main()
{
int a, b, c;
double r1, r2;
cout << "Enter values for a, b, and c to complete the quadratic formula: \n";
cin >> a;
cin >> b;
cin >> c;
if (quadratic(a, b, c, r1, r2))
{
cout << "Solution found: " << r1 << ", " << r2 << endl;
}
else
{
cout << "No real solution for this sorry!\n";
}
return 0;
}
bool quadratic(int a, int b, int c, double r1, double r2)
{
bool valid = true;
if (b * b - 4 * a * c < 0)
{
valid = false;
}
else
{
r1 =((-b + sqrt(double(b * b - 4 * a * c))) / (2 * a));
r2 =((-b - sqrt(double(b * b - 4 * a * c))) / (2 * a));
}
return valid;
}
|