The function assumes that every month is 31 days long (to add 1 to the month) but it can have days longer than 31. How do i determine the days of each month and is there an easier way to add the date by a function call to ctime?
Heres my code:
void enterLoanDate(int weeks)
{
t = time(NULL);
timePtr = localtime(&t);
int overflow = 0;
for (int i = 0; i <= (weeks * 7); i++)
{
dueDate.day = timePtr->tm_mday + i;
if (dueDate.day > 31)
overflow++;
}
if (overflow > 0)
dueDate.month = timePtr->tm_mon + overflow;
else
dueDate.month = timePtr->tm_mon;
if(dueDate.month < timePtr->tm_mon)
dueDate.year = timePtr->tm_year + YR + 1;
else
dueDate.year = timePtr->tm_year + YR;
}
This post has been edited by rethc: 07 August 2012 - 06:01 AM

New Topic/Question
Reply



MultiQuote





|