"lvalue required asleft opperand of assignment"

Hey, I have a code that uses the atan function but I want it to be able to say what the angle is given what quadrant you are in but I keep getting an error message (title) when I do it.

This is the part of the code that is getting the error

if(xRand < 0 && (yRand < 0 || yRand > 0))
atan(xRand/yRand) += pi;

I have defined pi = 4*atan(1) and am using #include<math.h>
atan(xRand/yRand) += pi;

Tell me what this line is trying to do.
If the x component is negative (which I guess I can get rid of yRand because it can be either positive or negative) then the angle will be off by pi so I want to add pi to the resulting angle to fix it.
And where will it be stored?
Even if would work, you wold discard resulting angle immideatly.
angle will be off by pi so I want to add pi to the resulting angle to fix it.
There is atan2() function for that:
Last edited on
Ooh, okay. I didn't know that. But what if I wanted the angles to be between 0 and 2pi, not -pi to pi? I just tried that same thing kinda but with:

if(atan2(xRand,yRand) < 0)
atan2(xRand,yRand) += (2*pi);

And got the same error. What can I do to fix it? I don't care about the old atan2 value in my program.
Ok, assume it was succesfull.
How will you get this value?
I use it in a function in an if statement right after. Will the value be deleted? Should I make it it's own function above my main one and call it?
No, it is not deleted. it is not stored anywhere.
What you doing is essentually this:
7 += 3;
You should assign resul of atan to a value first.
Like: double x = atan2(xRand,yRand);
Actually you are gerring wrong result here: it is atan2(yRand, xRand)
Yoiu can do something like:
double x = atan2(xRand,yRand);
x < 0? x+= 2*pi:x;
Ooohh, okay. That makes a lot of sense. I got it to work :). I appreciate this MiiNiPaa!
Topic archived. No new replies allowed.