{ This program asks the user for a year, and prints a calendar for that year. } program calendar (input, output); const JAN = 1; FEB = 2; MAR = 3; APR = 4; MAY = 5; JUN = 6; JUL = 7; AUG = 8; SEP = 9; OCT = 10; NOV = 11; DEC = 12; BLANK = ' '; var month, year, dayFor1st : integer; { Get the year from the user, and compute (using a magic formula) the day on which its January 1 falls. Sunday is 0, Monday 1, etc. The formula to find the first day of the given year was found in the book "A Collection of Programming Problems and Techniques", by H.A. Maurer and M.R. Williams (Prentice-Hall, 1972). } procedure GetYearInfo (var year, dayFor1st : integer); var y : integer; { We will only deal with years AD. } function Legal (year : integer) : boolean; begin Legal := (year > 0); end; begin {GetYearInfo} repeat write ('Please type the year you want a calendar for: '); readln (year); if not Legal (year) then begin writeln ('Can''t make a calendar for that year.'); end; until Legal (year); y := year - 1; dayFor1st := (36 + y + y div 4 - y div 100 + y div 400) mod 7; end {GetYearInfo}; #include "numdays.i"; #include "wkbywk.i"; begin {main program} GetYearInfo (year, dayFor1st); for month := JAN to DEC do begin PrintMonth (month, year, dayFor1st); dayFor1st := (dayFor1st+NumberOfDaysIn(month, year)) mod 7; end; end {main program}.