Jim I understand where your coming from, however I am a newbie to all this stuff. So, I think for me to understand all the logic is the best thing to accomplish first. I can always go back and learn functions later.
OK I have done this piece of code after searching. And from what I read the extra day is added on to the end of year total correct? So when entering 12/31/1996 it should give off a 366 day total.
CJ
Code:
#include <stdio.h>
int day_of_year(int a, int b, int c);
main()
{
int mth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int day=0, month=0, year=0;
printf("Enter the month in number form (ex. January being '1') : ");
scanf("%d", &month);
printf("Enter the date : ");
while ( scanf("%d", &day) != (day <= mth[month] + 1) || (day >= mth[month] + 1) )
printf("Not a valid date inside selected month! Try again! :");
printf("Enter the year : ");
scanf("%d", &year);
printf("The day of the year you selected was %d \n", day_of_year(month, day, year) );
}
int day_of_year(int a, int b, int c)
{
int i=0, daymon=0, dayday=0;
int mth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if ( (c % 4) || (c % 100) && (c % 400) )
mth[3] = mth[3] + 1;
for (i = 0; i < a; i++)
{
daymon += mth[i];
}
dayday = b;
return (daymon + dayday);
}