Day Number (Ex7-13, P.231)

  1. The days of the year are often numbered from 1 through 365 (or 366). For example, the "day number" of February 1st is 32, while the "day number" of December 31st is 365 (or 366 for a leap year).
  2. This number can be computed in three steps:
    1. dayNum = 31(month - 1) + day
    2. if the month is after February, subtract (4(month) + 23)//10
    3. if it's a leap year and after February 29, add 1
  3. Write a program that accepts a date as month/day/year, verfied that it is a valid date (see Ex7-12), and then calculates the corresponding day number.

The program may run as follows:

Input a date (month/day/year) -- 3/1/2014
60


Input a date (month/day/year) -- 3/1/2016
61