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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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.
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.

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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
evilrixSenior Software Engineer (Avast)Commented:
So, how's it going? Got any code to share with us yet?
TonyMannellaBusiness/IT AnalystAuthor Commented:
Thanks - looks like the way to go was with functions per Sara.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.