Computer Science, asked by deepakalphs914, 5 months ago

write a program in c ++ to input a date and check whether the entered date is valid or invalid using else if statement. here the header files are :-
#include<iostream.h>
#include<conio.h>
void main

Answers

Answered by yesiamin6
0

Answer:

#include <iostream>

using namespace std;

#include<conio.h>

int main()

{

int dd,mm,yy;

cout<<"Enter date (DD/MM/YYYY format):\n ";

cin>>dd>>mm>>yy;

if(yy>=1900 && yy<=9999)

{

if(mm>=1 && mm<=12)

{

if((dd>=1 && dd<=31) && (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12))

cout<<"Date is valid.\n";

else if((dd>=1 && dd<=30) && (mm==4 || mm==6 || mm==9 || mm==11))

cout<<"Date is valid.\n";

else if((dd>=1 && dd<=28) && (mm==2))

cout<<"Date is valid.\n";

else if(dd==29 && mm==2 && (yy%400==0 ||(yy%4==0 && yy%100!=0)))

cout<<"Date is valid.\n";

else

cout<<"Day is invalid.\n";

}

else

{

cout<<"Month is not valid.\n";

}

}

else

{

cout<<"Year is not valid.\n";

}

return 0;

}

Explanation:

I have used namespace std as I am using adv version of c++ compiler

If your pc support iostream.h then no need of using namespace std

Output is attached look at that

HOPE IT HELPS YOU

DO FOLLOW FOR MORE PROGRAMS

MARK AS BRAINLIEST

Attachments:
Similar questions