Link to home
Start Free TrialLog in
Avatar of TonyMannella
TonyMannellaFlag for United States of America

asked on

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
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
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
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So, how's it going? Got any code to share with us yet?
Avatar of TonyMannella

ASKER

Thanks - looks like the way to go was with functions per Sara.