The C programming language is one of the earliest and most popular programming languages. C has remained popular because it is efficient, portable and provides low-level memory access. Even though C was developed to design system software, it can also be used to develop application software. C can even be used in web development. C is capable of complex calculations. The calculation performed to determine the next day's date is one of the simplest.
- Skill level:
Other People Are Reading
Declare a class to hold the month, day and year. A two-digit day, a two-digit month and a four-digit year must be supplied to the function either by user input or from another application.
Perform validation on the data entered by calling a function to read the date, determine if it is a leap year and determine if the month and day are valid. An array is hard-coded with the end day for each month in order from January through December. For example, 31, 28, 31 are the first three numbers because January has 31 days, February has 28 and March has 31. The day digit is validated against this array.
Perform the same type of verification on the month entered to ensure that it is a valid value between 1 and 12. Again, an array with a list of valid months is created to perform the validation. Both the day and month validations should be separate functions.
Determine if the year entered is a leap year. If the year is evenly divisible by four, it is a leap year. Use the modulo -- remainder -- operator to perform this calculation.
Add one to the day, now that we have determined we have a valid day, month and year. If the day is beyond the current total number of days for the given month, then the month needs to be incremented and the day set to 1. If the date entered is the last day of the year, the year is incremented and the month and day are set to 1.
Display the newly calculated date to the user.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for