So in one of our assignments we have to have someone input the day of the year (ex. 59) and have it output the month and day (ex. 2/28). All we have to work with is an array that declares how many days are in each month.
I thought I had it beat with this code (for February):
But then I realized it's counting backwards! For example, putting in 57 gives me 2/2. Is there an easier way to do this?Code:else if((daysNmonth[1] + daysNmonth[2]) - dayOfYear >= 0) { dayOfMonth = daysNmonth[1] + daysNmonth[2] - dayOfYear; Month = 2; printf("Day %d of the year is %d/%d", dayOfYear, Month, dayOfMonth); }
Thanks in advance!