#include #include #include using namespace std; int main() { // Days in each month (assuming no leap years) int daysInMonth[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Get the current date time_t t = time(nullptr); tm *p = localtime(&t); int year = p->tm_year + 1900; int month = p->tm_mon + 1; int day = p->tm_mday; cout << "Current date: " << month << "/" << day << "/" << year << endl; cout << "How many days forward do you want to go? "; int distance; cin >> distance; if (distance < 0) { cerr << "Sorry, distance can't be negative.\n"; return EXIT_FAILURE; } // Advance years int yearsToAdd = distance / 365; year += yearsToAdd; distance -= yearsToAdd * 365; // Advance months int monthsToAdd = distance / 30; // Approximate 30 days per month month += monthsToAdd; distance -= monthsToAdd * 30; // Handle month while (month > 12) { month -= 12; year++; } // remaining days day += distance; while (day > daysInMonth[month]) { day -= daysInMonth[month]; month++; if (month > 12) { month = 1; year++; } } // new date cout << "The new date is: " << month << "/" << day << "/" << year << endl; return 0; }