C++ Programme
unknown
c_cpp
2 years ago
2.2 kB
1
Indexable
Never
#include <iostream> using namespace std; int difference, day, month, year, leapyear; int main() { cout << "\n Enter the difference in days and press Enter : "; cin >> difference; cout << "\n Enter a date in the form of DD MM YYYY and press enter: "; cin >> day >> month >> year; if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { leapyear = 1; } else { leapyear = 0; } day = day - difference; if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) { if (day > 30) { // day -= 30; month++; } else if (day < 1) { month--; day = day + 31; } } if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)) { if (day > 31) { day = day - 31; month++; if (month == 13) { month = 1; year++; } } if (day < 1) { month--; if (month == 0) { day = day + 31; month = 12; year--; } if (month == 2) { if (leapyear == 1) { { if (day > 29) { day = day + 29; month--; } else { if (day > 28) { day = day - 28; month++; } else { day = day + 30; } } } } } } } cout << "\n The final date is: " << day << "/" << month << "/" << year << endl; }