program assignment3_2a;

var x, y, stepx, stepy, r, theta, thetadeg:real;
    steps, output_num:integer;

procedure get_output(x, y:real; var r, theta, thetadeg:real);

begin

      r:=sqrt(sqr(x)+sqr(y));

      if x=0 then begin

        if y=0 then begin
          theta:=0;
          thetadeg:=0;
        end else if y>0 then begin
          theta:=3*Pi/2;
          thetadeg:=90;
        end else begin
          theta:=3*Pi/2;
          thetadeg:=270;
        end;

      end else if x<0 then begin
        theta:=arctan(y/x)+Pi;
        thetadeg:=theta*180/Pi;
      end else begin
        theta:=arctan(y/x);
        thetadeg:=theta*180/Pi;

        if y<0 then begin
          theta:=theta+2*Pi;
          thetadeg:=thetadeg+360;
        end;

      end;

end;

begin

  Randomize;

  steps:=0;
  output_num:=0;
  x:=0;
  y:=0;

  writeln(' steps |     x     |      y     |      r     | theta (rad) | theta (deg)');
  writeln('-------+-----------+------------+------------+-------------+-------------');

  get_output(x, y, r, theta, thetadeg);
  writeln(steps:6,' | ',x:8:4,'  |  ',y:8:4,'  |  ',r:8:4,'  |    ',theta:6:4,'   |   ',thetadeg:8:4);

  while steps<2000 do begin

    stepx:=Random*2-1;
    stepy:=Random*2-1;

    if ((sqr(stepx)+sqr(stepx))<=1) then begin

      steps:=steps+1;

      x:=x+stepx;
      y:=y+stepy;

    end;

    if ((steps mod 100)=0) and (steps>output_num) then begin

      output_num:=steps;

      get_output(x, y, r, theta, thetadeg);
      writeln(steps:6,' | ',x:8:4,'  |  ',y:8:4,'  |  ',r:8:4,'  |    ',theta:6:4,'   |   ',thetadeg:8:4);

    end;

  end;

  writeln();
  writeln('Press any key to continue.');
  readln;

end.
