I am doing my first code by myself. Everything up till now has been copy paste, make some changes to examples. I think I am heading in the right direction, but not sure.
#include <iostream>
#include <cmath>
using namespace std;
int main ( )
{
int a, b, c, x1, x2;
cout << "Please enter an integer value for a " << endl;
cin >> a;
cout << "Please enter an integer value for b " << endl;
cin >> b;
cout << "Please enter an integer value for b " << endl;
cin >> c;
cout << " The Quadratic Formula is: \n";
cout << " X = (-b +- sqrt ((b * b) - 4 * a * c)) \ (2 * a)\n";
cout << " \n";
x1 = sqrt((b * b)- 4 * a *c);
x2 = -sqrt((b * b) - 4 * a * c);
if (x1 < 0)
{
//use 1, 2, 3
cout << "There are no real roots 1";
cout << x1;
}
else if (x1 == 0)
{
//use 4, 12, 9
cout << "There is one real root ";
cout << x1;
}
else
{
//use 2, 11, 5
cout << "There are two real roots ";
cout << x1 << ", " << x2;
}
return 0;
}
If I enter three numbers when asked, it should calculate whether it has no real squares, one real square, or two real squares, and tell you the results. It seems to do that, but I am not sure if I got the math down. I did find some numbers that give individually expected results. I am not sure if I have put the correct math down, or if this could be done easier? Thanks ahead.