{*
 * Solution to Problem 3 (Pascal)
 * 11th Annual CS Programming Contest
 * WCU Dept of Math and CS
 * Copyright 2000 , All Rights Reserved
 *
 * Problem Description:  The user enters two dates from the keyboard.
 * This program outputs the number of days between the two dates.
 * (including the second date as one day if it differs fromt he first day).
 * Leap years are handled properly.
 *
 *
}


Program problem1(input,output);

{ symbolic constants for months }
Const JAN = 1;
Const FEB = 2;
Const MAR = 3;
Const APR = 4;
Const MAY = 5;
Const JUN = 6;
Const JUL = 7;
Const AUG = 8;
Const SEP = 9;
Const OCT = 10;
Const NOV = 11;
Const DEC = 12;

Var
{Year, month, and day one}
yOne, mOne, dOne: integer;
   
{Year, month, and day two}
yTwo, mTwo, dTwo: integer;

{This holds the number of days between the dates }
days: integer;


{
 * this function returns true
 * if the arguement is indeed a 
 * leap year -
 * A year is a leap year if it is
 * divisible by 400 or if it is
 * divisible by four but not by 100.
 *
}
function isLeapYear(year: integer) : boolean;
begin
  isLeapYear := (((year mod 400) = 0)
		 or (((year mod 4) = 0) and ((year mod 100) <> 0)));
end;



{ get the number of days in a whole year }
function daysInYear(year: integer) : integer;
begin
  if  isLeapYear(year) then
    daysInYear := 366
  else
    daysInYear := 365
end;


{ get the number of days in a whole month of a certain year }
function daysInMonth(month, year: integer) : integer;
var
  ans: integer;
begin
  case month of
  JAN: 
    ans := 31;
  FEB: 
    if isLeapYear(year) then
      ans := 29
    else
      ans := 28;
  MAR:
    ans := 31;
  APR:
    ans := 30;
  MAY:
    ans := 31;
  JUN:
    ans := 30;
  JUL:
    ans := 31;
  AUG: 
    ans := 31;
  SEP:
    ans := 30;
  OCT:
    ans := 31;
  NOV:
    ans := 30;
  DEC:
    ans := 31;
 end;

  daysInMonth := ans;

end;

   
begin {main}
   
   Writeln("Input the first date:");
   Read(mOne);
   Read(dOne);
   Readln(yOne);
   
   Writeln("Input the second date:");
   Read(mTwo);
   Read(dTwo);
   Readln(yTwo);
   
   if yOne < yTwo  then
   begin
      
      { Get days in rest of yOne. }
      while  mOne <= DEC do
      begin
	 { Get rest of days in mOne. }
	 days := days + daysInMonth(mOne, yOne) - dOne;
	 mOne := mOne + 1;
	 dOne := 0;
      end;
      
      { Now we are in the next year, so update. }
      yOne := yOne + 1;
      mOne := JAN;
      
      { We need to count Jan 1, so we start at Jan 0.
       See the line labeled A below. }   
      dOne := 0;   
      
      while yOne < yTwo do
      begin
	 days := days + daysInYear(yOne);
	 yOne := yOne + 1;
      end;           
   end;
   
   if mOne < mTwo then
   begin
      
      {Get rest of days in mOne }
      
      days := days + daysInMonth(mOne, yOne) - dOne; { A - see comment above }
      
      mOne := mOne + 1;
      dOne := 0; { Same reasoning as above - used in line labeled B. }
      
      while mOne < mTwo do
      begin
	 days := days + daysInMonth(mOne, yOne); { yOne == yTwo }
	 mOne := mOne + 1;
      end;     
   end;
   
   {Compute the remaining difference, which is within a month }
   days := days + dTwo - dOne; { B - see above. }
   
   { Output the difference. }
   if days = 0 then
   begin
      Writeln("There are no days between those dates")
   end else if days = 1 then
   begin
      Writeln( "There is 1 day between those dates")
   end
   else
   begin
      Write("There are ");
      Write(days);
      Writeln(" days between those dates");
   end;
   
End.
   
