I've made a few changes here but I'm still not getting what I expect to get. For example, when I substitute a for 1, b for 2 and c for 2, I should get -1+i and -1-i but when I run code it gives me -0.73205+i and - 2.73205+i. How do I fix this?
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double a, b, c, disc, x1, x2, root1, root2, imrt1, imrt2;
char i;
cout<<"Enter a, b and c ";
cin >> a >> b >> c ;
if(disc == 0.0 && b == 0.0)
cout<<"The equation is degenerate and has no real roots. \n";
else if(a == 0.0)
cout<<"The equation has one real root x = "<< -c/b <<endl;
else
{
disc = pow(b,2.0)-4*a*c;
if (disc > 0.0)
{
disc = sqrt(disc);
root1 = (-b+disc)/(2*a);
root2 = (-b-disc)/(2*a);
cout<<"The two real roots are "<<root1<<" and "<<root2<<endl;
}
else if(disc < 0.0)
disc = pow(b,2.0)+4*a*c;
disc = sqrt(disc);
imrt1 = (-b+disc)/(2*a);
imrt2 = (-b-disc)/(2*a);
cout<<"The two imaginary roots are "<<imrt1<<"+i"<<" and <<imrt2<<"+i"<<"\n";
else
cout<<"Both roots are equal to "<<-b/(2*a)<<endl;
}//End of compound statement for the outer else
system("PAUSE");
return 0;
}