0

I am doing a for loop to calculate the present value. When j = 1, I will get the correct product and sum, but when j goes to 2 till 20, the product will be just 0. may I know what did I miss out?

program q5
implicit none
integer :: j, k, lx, d, ld, row, col
real :: pv, v, qd, sum, product
real, dimension(110,3) :: arr

sum = 0.0
product = 0.0
lx = 0
ld = 0
qd = 0.0

!connect file
open( unit = 1, file = 'Females_Australian_Life_Tables_2010-12.csv' )

do row = 1, 110
    read( 1, *) arr(row,:)
    write(*,*) arr(row,:)
enddo

do j = 1, 20
    d = 66 + j - 1
    v = 1 / ( 1 + 0.05 )
    lx = arr(66,2)
    ld = arr(d,2)
    qd = arr(d,3)
    product = ( ld/lx ) * qd * (v**j)
    sum = sum + product
                            print*, '*************', lx, ld, qd, '**********'
                            print*, 'j=', j
                            print*, '        product                     ', product
                            print*, '        sum                         ', sum
enddo

pv = 30000 * sum

!disconnect file
close( 1 )

print*, 'The present value is', pv
end program q5

this is the error I have got

0 Answers0