Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for leapyear.rex

(view source code of leapyear.rex as plain text)

  1. /* LeapYear.rex                               */
  2. /* Check if the specified year is a leap year */
  3. /* Written by Rob van der Woude               */
  4. /* http://www.robvanderwoude.com              */
  5.  
  6. parse arg year dummy .
  7. if dummy <> "" then call Syntax
  8. if year  <> "" then do
  9. 	if pos( "?", year ) >    0 then call Syntax
  10. 	if year             <    0 then call Syntax
  11. 	if year             > 9999 then call Syntax
  12. end
  13. else do
  14. 	year = substr( date("S"), 1, 4 )
  15. end
  16.  
  17. leapyear = 0
  18. if year //   4 = 0 then leapyear = 1
  19. if year // 100 = 0 then leapyear = 0
  20. if year // 400 = 0 then leapyear = 1
  21.  
  22. if leapyear = 1 then do
  23. 	msg = year||" IS "
  24. end
  25. else do
  26. 	msg = year||" is NOT "
  27. end
  28. msg = msg||"a leap year"
  29. say
  30. say msg
  31. exit 0
  32.  
  33.  
  34. Syntax:
  35. 	say
  36. 	say "LeapYear.rex,  Version 1.00"
  37. 	say "Check if the specified year is a leap year"
  38. 	say
  39. 	say "Usage:  <REXX>  LEAPYEAR.REX  [ year ]"
  40. 	say
  41. 	say 'Where:  "<REXX>" is your Rexx interpreter:'
  42. 	say "                 - Windows:  REGINA.EXE or REXX.EXE, whichever you installed"
  43. 	say "                 - OS/2:     no need to specify, just rename script to *.cmd"
  44. 	say '        "year"   is any year between 0 and 9999'
  45. 	say
  46. 	say "Written by Rob van der Woude"
  47. 	say "http://www.robvanderwoude.com"
  48. 	exit 1
  49. return
  50.  

page last modified: 2024-02-26; loaded in 0.0204 seconds