The program works well and is correct but doesn't follow requirements to take keyboard input as ONE STRING variable that has to be parsed and the individual values converted to integers. I thought that was what I did, but it appears I'm wrong and I'm just short of ideas.
#include <stdio.h>
#include <stdbool.h>
int main()
{
int mm, dd,yyyy;
printf("Welcome to my Date Checker\n");
printf("Please enter date to test as format (MM/DD/YYYY): ");
scanf("%d/%d/%d", &mm, &dd, &yyyy);
// Validates year
if(yyyy>=1000 && yyyy<=9999)
{
// Validates month
if(mm>=1 && mm<=12)
{
// validate days
if((dd>=1 && dd<=31) &&
(mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12))
// Validates if jan, march, may, jul, aug, oct and dec
// have a max of 31 days
printf("Date is valid.\n");
else if((dd>=1 && dd<=30) && (mm==4 || mm==6 || mm==9 || mm==11))
// Validates if apr, jun, sept, and nov have max of 30 days
printf("Date is valid.\n");
else if((dd>=1 && dd<=28) && (mm==2))
// Validates if feb has max of 28 days
printf("Date is valid.\n");
else if(dd==29 && mm==2 && (yyyy%400==0 ||(yyyy%4==0 && yyyy%100!=0)))
// Validates leap years
printf("Date is valid.\n");
else
printf("Date is invalid.\n");
}
else { printf("Month is not valid.\n"); }
}
else { printf("Year is not valid.\n"); }
printf("\nPress any key to continue . . . ");
getchar();
}
The expected results are correct, just not the process.
Welcome to my Date Checker
Please enter date to test as format (MM/DD/YYYY): 03/25/1999
Date is valid.