Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.4 kB
2
Indexable
Never
```c++
#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 == 😎 || (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;
}
```
Hi, can someone help me with this code? I was testing my code and i wrote 7 days difference and 26 2 2020 as the date it gave me 33/2/2020. Someone help me fix it?