13.8k views
5 votes
Write a function named daycount() that accepts a month, day, and year as its input arguments; calculates an integer representing the total number of days from the turn of the century to the date that’s passed; and returns the calculated integer to the calling function. For this problem, assume each year has 365 days and each month has 30 days. Test your function by verifying that the date 1/1/00 returns a day count of 1.

Write a function named daycount() that accepts a month, day, and year as its input-example-1
User Kin
by
7.4k points

1 Answer

6 votes
return (year - 2000) * 365 + (month - 1) * 30 + day;

The rest is in the screenshot.

In reality you would never attempt to write something like this yourself. Leapyears/seconds will make it very hard to get right. There are library functions that can take care of this for you.
User Elias
by
8.8k points