How to find polar angle made by the line by joining the given point in cartesian plane with origin. I want a unique angle which will be from [0,2*pi)

Except (0,0), if I enter any point on coordinate axes I am not getting the correct answer. For example If I enter (1,-0.01) I should get an angle close to 2pi. On (1,0), I should get pi/2. For (-1,0), (0,-1) I should get pi and 3pi/2 respectively. Do I need to redefine atan function on the coordinate axes? Please help.

real x,y,s;
cout<<"Enter x-coordinate : ";
cin>>x;
cout<<"Enter y-coordinate : ";
cin>>y;
s=atan(y/x);
cout<<"Polar angle of the coordinate is : ";
cout<<s;

Use the function atan2: atan2(y,x)

Let f(x,y)=0 for (x,y)=(0,0) and f(x,y)=x^2/(x^2+y^2) for x^2>y^2 and f(x,y)=y^2/(x^2+y^2) for x^2<y^2. How to define a function with three cases.

Use conditionnal expression operator ?. It works as:

condition ? expression-true : expression-false

so for your question:

func f = ( (x==0.0 && y==0.0) ? 0.0 : ( x^2-y^2 > 0.0 ? x^2/(x^2+y^2) : y^2/(x^2+y^2) ) );