Question: *In c program need help explain *Need help it running but when putting either 12/33/2017 comes back as a good date which is incorrect, tried
*In c program need help explain
*Need help it running but when putting either 12/33/2017 comes back as a good date which is incorrect, tried putting in 02/29/2001 comes back as a good date which is incorrect
*if you can add additional comments please
*still learning go easy on me
*try not to do a flush or stdbool havent been taught that
*please help
*must convert to number with atoi, check for vaild rnages, and compare month num with day value
*below is what is asked
*if you can make adjustments with my program without adding new like fflush or bool please and i do need a loop
The entire purpose of the program is to test a single string entry from the keyboard for the possibility that the entry is a valid date. Other than taking a single string from the user at the keyboard, and reporting the validity (as described below), the entire program should be written as a single function that returns true (1) if the date is valid and false (0) if it is not valid
The program should accomplish testing th e keyboard entry and take one of two actions based on the validity of the entry.
1. If the entry is NOT a valid date the program should tell the user that the date is not valid .
2. If the entry is a valid dat e the program should notify the user that the date i s valid .
I expect heavy use of comments in the code of the program to explain what your code is accomplishing as you work through the validation process.
*my code below
#include
#include
#include
int main()
{
int month;//amount of months in the year
int day;//amount of days in the year
int year;//amount of years
int wrongdate = 1;//incorrect date
char string[15];//the string will be using, had ro make adjustments anything lower than 10 caused the string to crash
char date[20];
char *months;//period will be used for months
char *days;//period will be used for days
char *years;//period will be used for years
printf("Welcome to my Date Checker Project ");//will display my weclome
printf("Please enter a date as: MM/DD/YYYY ");//User will be asked to input the month, date, and year
gets(string);//the users input, gets is the same as scanf
//serval loops will be needed
if(strlen(string) != 10)//strlen means taking in a single argument in this case taking in our string
{
wrongdate = 0;
printf("It is the wrong date ");//will display wrong date if wrong
exit(1);
}
strcpy(date, string);//a copy will be needed, when ran would not recreate, strcpy and strtok will be needed
months = strtok(date, "/");
days = strtok(NULL, "/");//null is both a vaule and a pointer, also a seen as a 0 character
years = strtok(NULL, "/");
//atoi will be needed to convert a string into a number, might be needing
month = atoi(months);//will be converting the users input month into a number
day = atoi(days);//will be converting the users input date into a number
year = atoi(years);//will be converting the users input years into a number
//ran to see if it would build
//creating a loop
if(month == 0 || day == 0 || year == 0)//testing t
{
wrongdate = 0;
}
if(month < 0 || month > 12)
{
wrongdate = 0;
}
if(year <= 0)//if year is less than or equal to zero then its a wrongdate
{
wrongdate = 0;
}
switch(month)//switch will check each case
{
//if month
case 4://will be compared to either int or char
case 6://will be compared to either int or char
case 9://will be compared to either int or char
case 11://will be compared to either int or char
if(day > 30)
{
wrongdate = 0;
}
break;//break will end the loop
case 2:
if(year / 4 == 0)//divid year by 4
{
if(day > 29)// if day is greater than 29 then wrong date
{
wrongdate = 0;
}
if(day > 28 && year / 4 !=0)//if day is greater than 28 days and year is divide by 4 is not equal to zero then wrong date
{
wrongdate = 0;
}
break;//break will end the loop
}
}
if(wrongdate == 0)//if wrong will display
{
printf("It is the wrong date ");//if the user inputs a wrong date will display it else will display good date
printf("Press any key to continue.... ");
getchar();
}
else
{
printf("It is a good date ");//if the user inputs a good date it will display it else it will display wrong date
printf("Press any key to continue.... ");
getchar();
}
return 0;
}
//make adjustments was having run issues debug
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
