i have this from my book, but is there a better way to do it?
Code:int Date::checkDay (int TestDay) const { static const int daysPerMonth [ 13 ] = { 0, 32, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if ( testDay > 0 && testDay <= DaysPerMonth[ month ] ) return testDay; //February 29 check for leap yr if ( month == 2 && testDay == 29 && (year & 400 == 0 || (year % 4 == 0|| (year %4 == 0 && year % 100 !=0) ) ) return testDay; return 1; //leave object consistent, even if bad value }