Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
2.4 kB
3
Indexable
Never
#include <iostream>
using namespace std;
int main()
{
    int d, m, y;
    while(true)
    {   
        cout << "Nhap ngay: ";
    cin >> d;
    cout << "Nhap thang: ";
    cin >> m;
    cout << "Nhap nam: ";
    cin >> y;
        if((d<=0) || (m<=0) || (y<=0) || (m>12))
        {
            cout<<"Nhap lai di may thg lon\n ";
        }
        else {
            break;
        }
    }
    if ((m == 1) || (m == 3) || (m == 5) || (m == 7) || (m == 8) || (m == 10) )
    {
        if (d > 0 && d < 31)
        {
            d = d + 1;
            m +=0;
        }
        else if (d == 31)
        {
            d = 1;
            m += 1;
        }
        else if(d>31)
            {
                cout<<"Ngu nhu con bo,cook!\n";
                d=0; m=0; y=0;
            }
    }
    if (m == 2)
    {
        if (y % 4 == 0)
        {
            if (d > 0 && d < 29)
            {
                d += 1;
                m=2;
            }
            else if (d == 29)
            {
                d = 1;
                m = 3;
            }
            else if(d>29)
            {
                cout<<"Ngu nhu con bo";
            }
        }
        if (y % 4 != 0)
        {
            if (d > 0 && d < 28)
            {
                d += 1;
            }
            else if (d == 28)
            {
                d = 1;
                m = 3;
            }
            else if(d>28)
            {
                cout<<"Ngu nhu con bo,cook!\n";
                d=0; m=0; y=0;
            }
        }
    }
    if ((m == 4) || (m == 6) || (m == 9) || (m == 11))
    {
        if (d > 0 && d < 30)
        {
            d = d + 1;
            m+=0;
        }
        else if (d == 30)
        {
            d = 1;
            m += 1;
        }
        else if(d>30)
            {
                cout<<"Ngu nhu con bo,cook!\n";
                d=0; m=0; y=0;
            }
    }
    if (m==12)
    {
        if((d>0) && (d<31))
        {
            d+=1;
        }
        else if(d==31)
        {
            d=1; m=1; y+=1;
        }
        else if(d>31)
        {
            cout<<"Ngu nhu con bo,cook!\n";
            d=0; m=0; y=0;
        }
        
    }
    cout << d << "-" << m <<"-"<< y;
    system("pause");
}