How to Write a Program in C That Calculates Tomorrow's Date

Written by lora covrett
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Write a Program in C That Calculates Tomorrow's Date
The C programming language was developed around 1970 and is still popular today. (Stockbyte/Stockbyte/Getty Images)

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


  1. 1

    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.

  2. 2

    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.

  3. 3

    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.

  4. 4

    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.

  5. 5

    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.

  6. 6

    Display the newly calculated date to the user.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.