# 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
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Senior 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
Senior 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
Commented:
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

Experts Exchange Solution brought to you by