I have to input two dates, then subtract the earlier date from the later date, and output the number of days that is the difference. So for example April, 18 2012 - April 10, 2012 would come out as 8 days difference.
I've spent the last few days searching for an answer to this problem, along with several other problems. I've gone through several online resources, but most suggest using the DateTime class, which I can't use for this exercise, or converting the integers into days using the Julian conversion formulas, but I can't figure out how to get that to work in the overloaded operator.
I am completely and thoroughly stumped, and if anyone could point me in the right direction or post a link that leads to some helpful tips on how to do this, I'd be greatly appreciative. I'll give what code I have for the operation.
1 2 3 4 5 6 7 8 9 10
|
Date Date::operator - (const Date &right)
{
Date temp;
temp.year = year - right.year;
temp.month = month - right.month;
temp.day = day - right.day;
temp
return temp;
}
|
1 2 3 4 5 6 7 8 9 10 11
|
void Date::dateDiff()
{
int daysinyear[] = {0,31,59,90,120,151,181,212,243,273,304,334,365};
int days;
days = year * 365 + (year / 4);
days = days + daysinyear[month-1];
days = days + day;
return;
}
|
And this is how I'm trying to get this to work in main, but my << is overloaded to give a certain date format, so outputting Date3 this way doesn't work, because I'm trying to output an integer, but I don't know of any other way to do it.
1 2 3 4
|
cout << "The difference between the two dates is: " << endl;
Date3 = Date1 - Date2;
cout << Date3;
|