 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
lawchellie
Joined: 22 Dec 2011 Posts: 8
|
Posted: Thu Jan 26, 2012 12:34 pm Post subject: execution error owning to wrong input! |
|
|
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)*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
! accounting for february
if (n>(59+t))then
day=n+2-t
else
day=n
endif
month=(day+91)-(month*3055)/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! |
|
Back to top |
|
 |
Wilfried Linder
Joined: 14 Nov 2007 Posts: 314 Location: D�sseldorf, Germany
|
Posted: Thu Jan 26, 2012 3:32 pm Post subject: |
|
|
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:
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 |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|