For the if discriminant < 0 statement, I need to not only display the error message, but I must display the complex roots in the correct format for complex numbers. How should I go about that?
#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
int main()
{
int a = 0,
b = 0,
c = 0,
x1 = 0,
x2 = 0,
discriminant = 0;
cout <<"Enter value for A: ";
cin >> a;
cout <<"Enter value for B: ";
cin >> b;
cout <<"Enter value for C: ";
cin >> c;
x1 = (-b + sqrt ((b * b) - 4 * a * c)) / (2 * a);
x2 = (-b - sqrt ((b * b) - 4 * a * c)) / (2 * a);
discriminant = ((b * b) - 4 * a * c);
if ( a > 0 && discriminant > 0 )
cout <<"Value X equals: " << x1 <<" or "<< x2 <<'\n';
else
if ( a == 0 )
cout <<"Error"<<'\n';
else
if ( discriminant < 0 )
{
cout << "Error, roots will be complex, imaginary numbers." <<'\n';
}
else
if ( discriminant == 0)
cout <<"Roots will be identical: " << a << b << c << '\n';
return 0;
}