# include # include int main ( ) { int d; bool last_day; bool last_month; bool leap_year; int m; int y; printf ( "Enter date as m/d/y: " ); // // Notice that I include the slashes in the input format! // scanf ( "%i/%i/%i", &m, &d, &y ); // // Use boolean variables to remember the answers to these questions: // Is this a leap year? // Is this the last month of the year? // Is this the last day of the month? // leap_year = ( y % 400 == 0 ) || ( y % 4 == 0 && y % 100 != 0 ); if ( leap_year ) { printf ( "This is a leap year!\n" ); } last_month = ( m == 12 ); if ( last_month ) { printf ( "This is the last month of the year!\n" ); } last_day = false; if ( d == 28 && m == 2 && !leap_year ) { last_day = true; } else if ( d == 29 && m == 2 && leap_year ) { last_day = true; } else if ( d == 30 && ( m == 4 || m == 6 || m == 9 || m == 11 ) ) { last_day = true; } else if ( d == 31 && ( m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12 ) ) { last_day = true; } if ( last_day ) { printf ( "This is the last day of this month!\n" ); } // // Collecting the information was hard. // But now the computation is easy. // if ( last_month && last_day ) { y = y + 1; m = 1; d = 1; } else if ( last_day ) { m = m + 1; d = 1; } else { d = d + 1; } printf ( "Next day is %i/%i/%i\n", m, d, y ); return 0; }