Write day_of_year(year, month, day) to work out which day of the year it is. March 1, 2023 is day 60 (31 + 28 + 1). In a leap year February has 29 days, so March 1, 2024 is day 61. days holds the days in each month of a normal year, and days[0] is January.
day_of_year(2024, 3, 1)→61day_of_year(2023, 3, 1)→60day_of_year(2025, 12, 31)→365int day_of_year(int year, int month, int day)int day_of_year(int year, int month, int day) {
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// your code here: if it is a leap year, make February 29 days
int total = day;
for (int m = 1; m < month; m++) {
// your code here: add the days of month m to total
}
return total;
}
Run tries the examples. When they look right, Submit.