I’m trying to get this validation for a date entered, from Jan 01 1901 to Dec 31 2299, if the date is out of range, give a error message, this is my code, some how it doesn’t validate correctly, am I doing something wrong
int main (void)
{
// insert code here...
int day,month,year;
printf("Enter Year, Month and Day as YYYY,MM,DD\n");
scanf("4%d 2%d 2%d", &year, &month, &day);
if (year>1900 && year <2300) {
if (month>=1 && month <=12)
if (day >=1 && day <=31)
printf("correct/n");
else
printf("invalid/n");
}
return 0;
}
The problem is that you’re using nested if statements, but you don’t have enough else statements. If you simply consolidate the statements it should work.