i want to determine the day (sunday, monday, etc..) of a given date (ex: august 3rd, 2005). i have written a function which count the number of days into the year that the date is...example, feb 1st is 32 days into the year. i can't figure out how to do this though... i know that jan 1st, 1900 was a tuesday, but i really have no idea what to do with that . any suggestions?
also, i posted the code below because it seemed too easy and produced the right output the very first time.... any insight on possible errors which might occur in special cases? month, day, and year will always have valid values
Code://declared in date.h int Date::month; int Date::day; int Date::year; //dummy function until i confirm it's accuracy bool Date::isLeap(void) { return !(year % 4); } int Date::daysIntoYear(void) { if(month == 1) return day; int count = 31; int lastMonth = 31; for(int i = 2; i < month; i++) { if(lastMonth == 31) //if the last month had { //31 days, this month //has 30 days if(i != 8) ///<--unless this month { //is august lastMonth = 30; } count += lastMonth; }else{ lastMonth = 31; count += lastMonth; } } if(month > 2) //if past Feb, remove { //1 or 2 days (if leap 1, else 2) if(isLeap()){ count--; }else{ count -= 2; } } return (count + day); }



LinkBack URL
About LinkBacks


