Basic4GL Leap Year Calculator


Basic4GL Leap Year Calculator

 

  1. ' Leap Year Calculator
  2.  
  3. ' Declare our leap year function
  4. declare function leapyear(year)
  5.  
  6. ' Declare any variables here
  7. dim x
  8.  
  9. ' Main loop
  10. do
  11.  
  12.     ' Clear the screen
  13.     cls
  14.  
  15.     ' Ask the User to input a year
  16.     input "Enter a Year" ; x
  17.  
  18.     ' Print the result on the screen
  19.     if leapyear(x) then
  20.         print "Leap year"
  21.     else
  22.         print "Normal year"
  23.     endif
  24.  
  25.     ' Wait 1 second
  26.     sleep(1000)
  27.  
  28. loop
  29.  
  30. ' A description of how the leap year function works
  31.  
  32. ' "Every year that is exactly divisible by four is a leap year,
  33. '  except for years that are exactly divisible by 100; the centurial
  34. '  years that are exactly divisible by 400 are still leap years."
  35. '
  36. ' For example, the year 1900 wasn't a leap year but the year 2000 was.
  37.  
  38. function leapyear(year)
  39.     return (year % 4 = 0) and (year % 100 <> 0) or (year % 400 = 0)
  40. endfunction