I should check if month is 1 through 12,day is 1 through daysOfMonth[month], or
ID: 3618306 • Letter: I
Question
I should check if month is 1 through 12,day is 1 through daysOfMonth[month], or day is 1 throughdaysOfMonth [month]+1 if year is a leap year (use function 5.below) and year is 1000 through 9999, return –1 in a returnstatement if NOT. Then calculate the Day-of-year date given theCalendar date USING THE ARRAY OF DAYS PER MONTH. Remember to add 1to the Day-of-year date if the date is after Feb. 28 and the yearis a leap year (leap year function specs below – see 5.below). Return the Day-of-year date in a returnstatement. This is what I have so far but I keepgetting the wrong answer: int convertDateToDayOfYear ( intdaysOfMonth [], int month, int day, int year ){
int i;
int sum;
int dayOfYear;
if( month >= 1 && month <= 12 && day >= 1&& day <= daysOfMonth [month] && year > 1000&& year < 9999 )
if( determineLeapYear ( year ) == 1 && month > 2 || day> 28 )
for( i=0, sum=0; i < month; i++ )
{
sum += daysOfMonth [i];
dayOfYear = sum + day + 1;
}
else
for( i=0, sum=0; i < month; i++ )
{
sum += daysOfMonth [i];
dayOfYear = sum + day;
}
else
return -1;
return dayOfYear;
}
int determineLeapYear ( int year )
{
if( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 1; /* a leap yaer */
else
return 0; /* not a leap year */
} My input file is: 5 4 1987
2 22 2004
8 9 2000
2 29 1900
3 2 2001
1 8 1999
9 31 2001
9 30 201
12 31 2004
22 9 2000
2 29 2000 And the out put should be: 124 53
222
61
8
366
60 <= (only this one doestn't show in my output, theproblem I have is that I keep getting a -1 for 2 29 2000 anddon't know how to fix it) Thank you I should check if month is 1 through 12,day is 1 through daysOfMonth[month], or day is 1 throughdaysOfMonth [month]+1 if year is a leap year (use function 5.below) and year is 1000 through 9999, return –1 in a returnstatement if NOT. Then calculate the Day-of-year date given theCalendar date USING THE ARRAY OF DAYS PER MONTH. Remember to add 1to the Day-of-year date if the date is after Feb. 28 and the yearis a leap year (leap year function specs below – see 5.below). Return the Day-of-year date in a returnstatement. This is what I have so far but I keepgetting the wrong answer: int convertDateToDayOfYear ( intdaysOfMonth [], int month, int day, int year )
{
int i;
int sum;
int dayOfYear;
if( month >= 1 && month <= 12 && day >= 1&& day <= daysOfMonth [month] && year > 1000&& year < 9999 )
if( determineLeapYear ( year ) == 1 && month > 2 || day> 28 )
for( i=0, sum=0; i < month; i++ )
{
sum += daysOfMonth [i];
dayOfYear = sum + day + 1;
}
else
for( i=0, sum=0; i < month; i++ )
{
sum += daysOfMonth [i];
dayOfYear = sum + day;
}
else
return -1;
return dayOfYear;
}
int determineLeapYear ( int year )
{
if( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 1; /* a leap yaer */
else
return 0; /* not a leap year */
} My input file is: 5 4 1987
2 22 2004
8 9 2000
2 29 1900
3 2 2001
1 8 1999
9 31 2001
9 30 201
12 31 2004
22 9 2000
2 29 2000 And the out put should be: 124 53
222
61
8
366
60 <= (only this one doestn't show in my output, theproblem I have is that I keep getting a -1 for 2 29 2000 anddon't know how to fix it) Thank you