Sunday, 17 February 2019

C++ Program to Check Whether a given date is valid or not

#include <iostream>

using namespace std;

int main()
{
    int dd,mm,yy,v;
    cout<<"Enter the Date\n";
    cin>>dd>>mm>>yy;
    if((yy<0) || (mm<1) || (mm>12) || (dd>31) || (dd<1))
        v=0;
    else if(((mm==4) || (mm==6) || (mm==9) || (mm==11)) && (dd>30) )
    v=0;
    else if((mm==2) && (yy%4==0) && (dd>29))
    v=0;
    else if( (mm==2) && (dd>28))
        v=0;
    if(v==0)
        cout<<"\nDate is Invalid\n";
        else
            cout<<"\nDate is valid\n";

    return 0;
}

OUTPUT:-

Enter the Date
14
02
2019

Date is valid

No comments:

Post a Comment