Silverfrost Forums

Welcome to our forums

execution error owning to wrong input!

26 Jan 2012 11:34 #9500

implicit none integer :: year, n, month, day, t ! t is an offset to account for leap years. print*, 'year, followed by day within year' read*, year, n ! checking for leap years if ((year/4)4year)then t=1 if ((year/400)*400year)then t=1 elseif ((year/100)100==year)then t=0 endif else t=0 endif ! accounting for february if (n>(59+t))then day=n+2-t else day=n endif month=(day+91)-(month3055)/100 month=month-2 print, 'calendar date is ', day, month, year

      end

hello! pls am wondering what i am suppose to enter under the i/o

read*, year, n though the compilation appear correct but confuse what to enter as input argument, help pls if possible with an example. thank u!

26 Jan 2012 2:32 #9503

Hi,

it seems that the programme calculates the date from day and year, for instance the input of '2012 100' should give the 9th of April, 2012. Your input: Key in 2012, followed by a blank, followed by 100.

But the algorithm is wrong and lead to funny results. Here's the modified code:

      PROGRAM test 
      WINAPP 

      implicit none 
      integer :: year, n, month, day, t 

      integer*4  i,j,tt(12)

      print*, 'year, followed by day within year' 
      read*, year, n 

      if ((year/4)*4==year)then 
        t=1 
        if ((year/400)*400==year)then 
          t=1 
        elseif ((year/100)*100==year)then 
          t=0 
        endif 
      else 
        t=0 
      endif 

      tt(1)  = 31
      tt(2)  = 28+t
      tt(3)  = 31
      tt(4)  = 30
      tt(5)  = 31
      tt(6)  = 30
      tt(7)  = 31
      tt(8)  = 31
      tt(9)  = 30
      tt(10) = 31
      tt(11) = 30
      tt(12) = 31

      j = tt(1)
      day = n
      do i = 1,12
        if (n .le. j) then
          month = i
          exit
        end if
        day = day-tt(i)
        if (i .lt. 12) then
          j = j+tt(i+1)
        else
          month = 12
        end if
      end do

      print*, 'calendar date is ', day, month, year 

      end

Regards - Wilfried

Please login to reply.