! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

! Example 4.15. Estimate the area of a quadrant of a circle.
  program E15
    implicit none
    real :: Total, Hits
    real, dimension(2) :: X
    integer :: How_Many, Loop, Tries
! start program E15
    Total = 0.0
    Hits = 0.0
    How_Many = 0.0
    do
      write (unit = *, fmt = *) " How many more tries? (Enter zero to quit.) "
      read (unit = *, fmt = *) Tries
      if (Tries <= 0) then
        exit
      end if
      do Loop = 1, Tries
        How_Many = How_Many + 1
        Total = Total + 1
        call random_number( Harvest = X ) ! Vector of two random numbers
        if (X(1) ** 2 + X(2) ** 2 < 1.0) then
          Hits = Hits + 1.0
        end if
      end do
      write (unit = *, fmt = *) How_Many, " Estimated area is now: ", Hits / Total
    end do
    stop
  end program E15
