// Number of days between two dates. // Michael Rothstein // 3/5/2014 #include using std::cin; using std::cout; using std::endl; struct date{ int month; int day; int year; }; int day_in_year(date); int main(){ date d1,d2; cout << "What is the first date?"; cin >> d1.month >> d1.day >> d1.year; cout << "What is the second date?"; cin >> d2.month >> d2.day >> d2.year; int days1 = day_in_year(d1); int days2 = day_in_year(d2); int years = d2.year - d1.year; int difference = 365*years + days2 - days1; cout << "There are " << difference << " days between the two dates.\n"; } int days[]={0,31,59,90,120,151,181,212,243,273,304,334,365}; int day_in_year(date d){ return days[d.month-1]+d.day; }