Validating date in c

Rated 4.93/5 based on 752 customer reviews

Years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years.This keeps the our calendar years in sync with earth's revolutions around the sun.Observe that the %d format Specifiers in the scanf format string are separated by '/' characters as "%d/%d/%d".Such non-format characters in the format string of the scanf statement must be entered by the user at the indicated position.Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

the program prompts for month input until it is in the range [1;12]. If you want to run the program again, after its first execution, move the whole code to a separate function, and execute it in the loop: i tried to do it like this..working ....again there's something wrong with the validation (switch part of it...) like this; enter month:4 enter day:31 enter year:2008 the result is Valid but that should be invalid because its april.. i think my switch case is not help me figure it out? same as "do you want to try again.." if i put bool its error..compiler is turbo c only...

Let us use variables dd,mm and yy (all of type int)to represent the day, month and year in a given date.

The given date is valid only if year (yy)is non-zero, month (mm)is in the range 1 to 12 and day of month (dd) is in the range 1 to mdays, the number of days in a given month mm.

Here's a small portion of a datetime class I made once: Note that this assumes all dates use the gregorian calendar, so dates prior to ~1582 might give incorrect results.

I'm not completely sure how that whole calendar conversion stuff altered results, but anyway.

Leave a Reply