Question: Created this C language program for the following assignment: Write a program that determines the day number (1 to 366) in a year for a

Created this C language program for the following assignment: Write a program that determines the day number (1 to 366) in a year for a date that is provided as input data. As an example, January 1st, 1994, is day 1. December 31, 1993, is day 365. December 31, 1996 is day 366, since 1996 is a leap year. A year is a leap year if it is divisible by four, except that any year divisible by 100 is a leap year only if it is divisible by 400. Your program should accept the month, day, and year as integers. Include a function leap that returns 1 if called with a leap year, 0 otherwise. I cannot get it to run and execute. Help.

#include

int GetDayNumber(char month[10], int day, int year);

int Leap(int Year);

int main()

{

char month[10];

int day, year, dayNumber;

printf("Enter a date (Ex. January 1, 2001):");

scanf("%s%d%d", &month, &day, &year);

dayNumber = GetDayNumber(month, day, year);

printf("Day number for this date: %d ", dayNumber);

getchar();

return 0;

}

int GetDayNumber(char month[10], int day, int year)

{

int days = 0;

if (month, "January" == 0)

days = day;

else

if (month, "February" == 0)

days = 31 + day;

else

if (month, "March" == 0)

days = 31 + 28 + day;

else

if (month, "April" == 0)

days = 31 + 28 + 31 + day;

else

if (month, "May" == 0)

days = 31 + 28 + 31 + 30 + day;

else

if (month, "June" == 0)

days = 31 + 28 + 31 + 30 + 31 + day;

else

if (month, "July" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + day;

else

if (month, "August" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day;

else

if (month, "September" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day;

else

if (month, "October" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;

else

if (month, "November" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;

else

if (month, "December" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;

else

{

printf("Invalid Month Name.");

return 0;

}

if (month, "January") != 0 && (month, "February") != 0 && Leap(year))

days++;

return days;

}

int Leap(int year)

{

if ((year % 400 == 0)

|| (year % 4 == 0 && year % 100 != 0))

return 1;

else

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!