how to write a program that can accept a date from user and print the day on which it occurs

7 Years
Discussion Span
Last Post by Ancient Dragon

Er, did you mean to start a poll with a random question in it?

To answer your (post) question:

  1. Read in a date from the user as std::string
  2. Parse the string to extract the day, month, year etc.
  3. Calculate the number of days from the date the user entered to some reference date, on which you know the day (eg. today).
  4. Use numberOfDays%7 to get the answer.

Have fun.


I voted yes. Partly, because I am psychic and I can tell the OP's code is thousands of pages long.

Edited by iamthwee: n/a


The struct tm in time.h or ctime contains an integer that represents the day of the week. After getting the date from the keyboard just fill in a struct tm and pass it to mktime() to complete the structure. You must zero out all the elements of the structure before doing that.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.