hello!
I need a program that validates the imput of dates. (Checks for leap years etc.)
The user enters: mm/dd/yyyy
The problem is, I have trouble with complex programs. I came up with this program, but i know it's too basic for what she wants. I need to have arrays in there, but i don't know how. I would love any help considering I'm bad at understanding this subject.
:)
could someone help me ???!!!
bool GoodDate(int month,int day,int year)
{
/*** Bad Month ***/
if(month < 1 || month > 12)
return false;
/*** January ***/
else if(month == 1)
{
if(day >=1 && day<= 31)
return true;
else
return false;
}
/*** Febuary ***/
else if(month == 2) // divisible by 4 and either divisible by 400 or not divisible by 100
{
/*** if the year is a leap year... ***/
if(year % 4 == 0 && (year % 400 == 0 || year % 100 != 0))
{
if(day >= 1 && day <= 29)
return true;
else
return false;
}
/*** if the year is not a leap year... ***/
else
{
if(day >=1 && day <= 28)
return true;
else
return false;
}
}
/*** March ***/
else if(month == 3)
{
if(day >=1 && day<= 31)
return true;
else
return false;
}
/*** April ***/
else if(month == 4)
{
if(day >=1 && day<= 30)
return true;
else
return false;
}
/*** May ***/
else if(month == 5)
{
if(day >=1 && day<= 31)
return true;
else
return false;
}
/*** June ***/
else if(month == 6)
{
if(day >=1 && day<= 30)
return true;
else
return false;
}
/*** July ***/
else if(month == 7)
{
if(day >=1 && day<= 31)
return true;
else
return false;
}
/*** August ***/
else if(month == 8)
{
if(day >=1 && day<= 31)
return true;
else
return false;
}
/*** September ***/
else if(month == 9)
{
if(day >=1 && day<= 30)
return true;
else
return false;
}
/*** October ***/
else if(month == 10)
{
if(day >=1 && day<= 31)
return true;
else
return false;
}
/*** November ***/
else if(month == 11)
{
if(day >=1 && day<= 30)
return true;
else
return false;
}
/*** December ***/
else if(month == 12)
{
if(day >=1 && day<= 31)
return true;
else
return false;
}
else
{
cout<<"Error\n";
exit(0);
}
return false;
}