disp('Calculates the day of year given the current date');
month = input('Enter month 1-12: ');
day   = input('Enter day 1-31: ');
year  = input('Enter year yyyy: ');

if mod(year,4) == 0
   leap_day = 1;
else
   leap_day = 0;
end
if mod(year,100) == 0
   leap_day = 0;
end
if mod(year,400) == 0
   leap_day = 1;
end

day_of_year = day;
for ii = 1:month-1
   switch (ii)
   case {1,3,5,7,8,10,12},
      day_of_year = day_of_year + 31;
   case {4,6,9,11},
      day_of_year = day_of_year + 30;
   case 2,
      day_of_year = day_of_year + 28 + leap_day;
   end
end

fprintf('The date %2d/%2d/%4d is day of year %d.\n', ...
         month, day, year, day_of_year);

