I don't Know Why The Result Is correct for the subtraction -=
and wrong for sum +=
Need Help
#include<iostream>
using namespace std;
class complex {
float r , im ;
public:
complex (float a ,float b)
{
r=a;
im=b;
}
complex& operator+= (complex &x)
{
r=r+x.r;
im=im+x.im;
return * this;
}
complex& operator-= (complex &x)
{
r=r-x.r;
im=im-x.im;
return * this;
}
complex& operator*= (complex &x)
{
r=r*x.r;
im=im*x.im;
return * this;
}
complex& operator/= (complex &x)
{
r=r/x.r;
im=im/x.im;
return * this;
}
friend void show (complex &x)
{cout<<x.r<<"+i"<<x.im<<"\n";}
};
void main()
{
complex m(10,20) , n(15,30);
m-=n;
show(m);
m+=n;
show(m);
system("pause");
}
isn't it correct for both of them?
The result should be 10 + 20i and that seems to be the case
No the sum must me 25+50 i
not 10+20 i
because 10+15=20
and 20+30 =50
So ,,, what is the problem
Yeah, but when doing m -= n you modify m, right?
So after m-=n you have -5 | -10
after that you do m+=n and you should get 10|20 then again
Yes I know i modified it
but i want to know how to make "m+=n" use the numbers without modification of "m-=n"
what i meant that i want to "m+=n" to use number (10,15) and (20,30) even after using
"m-=n"
I hope you get it because my English is bad :(