I began teaching myself programming 3 weeks ago. Its hard (for me) i'm trying to include some date validating within a program i am writing.
this is what i have so far, but invalid dates are validated unfortunately.
eg. November 31 2010
or february 30 2012
have a look and help me out please
#include <iostream.h>
#include <conio.h>
int main()
{
int day,dd,mm,yy,num;
char ans;
clrscr();
do{
cout<<"Enter Month: \n";
cin>> mm;
}while (mm<1||mm>12);
do{
cout<<"Enter Day: \n";
cin>> dd;
}while (dd<1||dd>31);
do{
cout<<"Enter Year: \n";
cin>> yy;
}while (yy<1||yy==num);
// validation
switch (mm){
case 1: if (1,3,5,7,8,10,12);
day=31;
break;
case 2: if (4,6,9,11);
day=30;
break;
case 3 :
if(((yy%4==0)&&(yy%100!=0))||(yy%400==0))
day=29;
else
day=28;
}
if (dd, mm, yy)
cout<<"The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is VALID!"<<endl;
else
cout<< "The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is INVALID!"<<endl;
do{
cout<<"do you want to try again?? (Y/N) "<<endl;
cin>>ans;
} while (ans!='n'&&ans!='N');
getch();
}