## skorm909

The program I'm writing is supposed to take a number of tosses entered by the user, this part works.
Then take that and check to see if it is within a circle that is inside of a square. Then take the number that are inside the circle, and divide it by the number of tosses and the answer should be close to 3.14 the more tosses you choose.

here's my code so far, it works all good except the number is not close to pi at all.

``````--                                                     --
-- This program estimates the area of a circle         --
-- using Monte Carlo Integration.                      --
---------------------------------------------------------

PROCEDURE Circlepi IS
Gen : Generator;
Finished_Program, Samples_Inside_Circle : Integer;
Yes_No : Character;
Number_Of_Samples: integer;
X, Y : float;
estimate_of_pi : float;

BEGIN

Finished_Program := 0;
Samples_Inside_Circle := 0;
Estimate_Of_Pi := 0.0;
Number_Of_Samples := 0;
X := 0.0;
Y := 0.0;

WHILE (Finished_Program = 0) LOOP
Put("Enter the number of Samples: ");
Get (Number_Of_Samples);
FOR I IN 1 .. Number_Of_Samples LOOP
X := 2.0*Random(Gen) - 1.0;
Y := 2.0*Random(Gen) - 1.0;
IF X*X + Y*Y < 1.0 THEN
END IF;
END LOOP;
Estimate_Of_Pi := float (Samples_Inside_Circle) / float (Number_Of_Samples);
Put ("Estimate of Pi: ");
Put (Estimate_Of_Pi);
new_line;
Put ("Do you want to run it again? (y)/(n)");
Get(Yes_No);
IF (Yes_No = 'n' or Yes_No = 'N') THEN
Finished_Program := 1;
END IF;

END LOOP;
END;
``````

## noelthefish 5

ok my maths have not been tested in 20 years but I am sure that what you are producing here should follow this

p = m/n
Pi = (approx) p * 4 <- this is the line you are missing. you only ouput the ratio.