errors/days-in-month-implementation.c - Selve funktionen daysInMonth - fokus på de funktionelle krav snarere end funktionens implementation. | Lektion 7 - slide 14 : 25 Program 4 |
/* Returns the number of days in month, in the given year. Input: month is an integer between 1 and 12. year is a legal year (a non-negative integer). Output: The number of dayns in month in the given year. An integer. */ int daysInMonth(int month, int year){ int numberOfDays; switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: numberOfDays = 31; break; case 4: case 6: case 9: case 11: numberOfDays = 30; break; case 2: if (isLeapYear(year)) numberOfDays = 29; else numberOfDays = 28; break; default: exit(-1); break; } return numberOfDays; }