# Thread: Complex number in qudratic equation C++

1. ## Complex number in qudratic equation C++

hi I need help with this program, I have to write an easy code for complex number thank you

if I put a=1, b=2. c=2 then I should get x=-1+j.1 and y=-1-j.1. I am an engineer so I use j instead of i.

#include <iostream>
#include <math.h>

using namespace std;

int main()

{
float a=0.0;
float b=0.0;
float c=0.0;
float d=0.0;
float x=0.0;
float y=0.0;

cout <<"value of a:";
cin>>a;
cout <<"value of b:";
cin>>b;
cout <<"value of c:";
cin>>c;

d=sqrt(b*b-4*a*c);
x=(-b+d)/(2*a);
y=(-b-d)/(2*a);

if (x==y)
{
cout<<"Both roots are equal\n";
}
else(x!=y)
{
cout<<"The roots are not the same\n";
}

cout<<x;
cout<<y;
cout<<"\n";

return 0;

}

2. Come back when you've learnt to read
http://cboard.cprogramming.com/showthread.php?t=13473

3. Code:
```else(x!=y)
{
cout<<"The roots are not the same\n";
}```
Try just 'else' not with the (x!=y)

4. man I just asked u didnt had to eat my head
is that forum is for when u don know ask other people thats what I am doing

now thank you jawib

5. Eating heads?? Salem pointed out that if you post code you use codetags. Nothing more, nothing less, but some people can/will be annoyed when you post code without codetags, especially since there is a sticky saying that you should/must use codetags.

6. also realize that there is a standard complex class in <complex>

Popular pages Recent additions