# How to add Days to a Date?

• 03-20-2002
Bufferlo
How to add Days to a Date?
I want my program to have a date input in the format of (dd, mm, yyyy), then another input in terms of the number of day(just an integer). And then I want my programm to have an out put of another date (in form of dd, mm, yyyy again). The algorithm is something like: Output_Date = Input_Date + days. I cannot find a simple algorithm.
Can anyone helps? Thanks.
• 03-20-2002
Esparno
Quote:

The algorithm is something like: Output_Date = Input_Date + days. I cannot find a simple algorithm.
uh...that is the algorithm, all you have to do is slap a ; at the end and you will be all set, oh, and make the cin statements, i ASSume u know how to do that.... but u know what happens when u ASS-U-ME
• 03-20-2002
Bufferlo
Furthermore, I don't want to use Julian Days.
Can anyone use Georgian Calenar to formulate an relatively easy algorithm?
• 03-20-2002
```#include <iostream> #include <cstdio> using namespace std; // this follows Gregorian rules bool isLeapYear(int year) {         if (year%400==0) return true;         if (year%100==0) return false;         return (year%4==0); } int main() {         int daysPerMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };         int day,month,year, daysToAdvance;         char line[81];         cout << "Enter date (dd, mm, yyyy): ";         cin.getline(line, 80);         sscanf(line, "(%i, %i, %i)", &day, &month, &year);         cout << "Enter days to advance: ";         cin >> daysToAdvance;         for (int i=0;i<daysToAdvance;i++)         {                 day++;                 if (day > daysPerMonth[month-1] || ( month==2 && day==29 && !isLeapYear(year) ) )                 {                         day = 1;                         month++;                         if (month==13)                         {                                 month = 1;                                 year++;                         }                 }         }         char output[80];         _snprintf(output, 80, "(%02i, %02i, %04i)", day, month, year);         cout << "Result: " << output << endl;         fflush(stdin);         getchar();         return 0; }```