C++ problem

I am trying to create a program in C++.... if the user enters a day the year (1-365), then  display the month and the day of the month.

For example
 
Enter a day of the year : 257
Day number 257 is on September 14


Thank you
TonyMannellaBusiness/IT AnalystAsked:
Who is Participating?
 
sarabandeCommented:
you may look to struct tm in time.h (see http://www.cplusplus.com/reference/ctime/tm/)

the structure has members tm_year and tm_ydays and you could use functions mktime and asctime to get the tm_mon (month) and tm_mday (day of month) filled.

Sara
0
 
evilrixSenior Software Engineer (Avast)Commented:
So, what code have you written so far that we might look at to assist you? I assume this is an academic exercise? If so, we are very happy to help you figure out the solution for yourself but you need to show us what you've done so far so we can gauge where and how to help you.
0
 
evilrixSenior Software Engineer (Avast)Commented:
Incidentally, with the exception of leap years this is just simple math. You know how many days there are in each month so given the number of days you can just count forward for the number of days in each month until you can go no further. That is your month and the remainder is the day of that month.

Leap years mess things up but if you are not putting in a specific year (you don't say you do) then you can probably just assume 28 days in Feb. If you do need to take leap years into consideration, there are some well known and easy to follow algorithms to figure that out. The basic algorithm goes something like this:

A year that is evenly divisible by 100 (for example, 1900) is a leap year only if it is also evenly divisible by 400. This is because they are evenly divisible by 100 but not by 400.

http://www.wikihow.com/Calculate-Leap-Years
0
 
evilrixSenior Software Engineer (Avast)Commented:
So, how's it going? Got any code to share with us yet?
0
 
TonyMannellaBusiness/IT AnalystAuthor Commented:
Thanks - looks like the way to go was with functions per Sara.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.