Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*THIS SHOULD BE IN C CODE* You are asked to enter the month and the day (as inte

ID: 3595821 • Letter: #

Question

*THIS SHOULD BE IN C CODE*

You are asked to enter the month and the day (as integers) to determine what season it is. Recall that the seasons changes on the 21st of March, June, September, and December. To do this, you will ask the user to enter the month and day in main. You should check that the month entered is valid (i.e., between 1 and 12). If the month entered is not valid, print a message saying that and use the exit(0); statement to end the program immediately. To use this statement, you will need to include the stdlib.h library.

We first need to make sure the day entered is valid since some months have 30 days, some have 31 days, and one has 28 days (assume no leap year). We will create a function called check_day that will handle making sure the day entered is valid. The simplest way to handle this is to use if statements to check groups of months that have the same number of days. If the day entered is invalid, print an appropriate error message and use the exit(0); statement.

Once we know the day entered is valid for the corresponding month, we need to determine the season. Use the function comp_season. This function will declare an integer variable for tracking the season. For example, the value 1 could correspond to winter, the value 2 could correspond to spring, 3 could correspond to summer, and 4 could correspond to fall. This function must use a switch for the month variable to handle each case. For example, in case 1, set the season variable to the value corresponding to winter. Remember that the season changes for certain months. The function should return the season number.

After determining the season number, we need to print the result. Use the function print_season to handle this. Since the value of the season variable is 1-4, we can use another switch and print the corresponding result.

An example of the output is as follows:

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

int number_of_days_in_month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
void checkDay(int day, int month) {
if (day < 1 || day > number_of_days_in_month[month-1]) {
printf("Day is not write it should be between 1 and %d ", number_of_days_in_month[month-1]);
exit(0);
}
}

int comp_season(int day, int month) {
switch(month) {
case 1:
case 2:
return 1;
case 3:
if(day < 21) return 1;
return 2;
case 4:
case 5:
return 2;
case 6:
if(day < 21) return 2;
return 3;
case 7:
case 8:
return 3;
case 9:
if(day < 21) return 3;
return 4;
case 10:
case 11:
return 4;
case 12:
if(day < 21) return 4;
return 1;
}
}

void print_season(int season) {
printf("The season is ");
switch(season) {
case 1:
printf("winter. ");
break;
case 2:
printf("spring. ");
break;
case 3:
printf("summer. ");
break;
case 4:
printf("autumn. ");
break;
}
}

int main()
{
int month, day;
printf("Enter the month as a number: ");
scanf("%d", &month);
  
if (month < 0 || month > 12) {
printf("Month is not valid. It should be between 1 and 12 ");
exit(0);
}
  
printf("Enter the day as a number: ");
scanf("%d", &day);
checkDay(day, month);
  
int season = comp_season(day, month);
print_season(season);
return 0;
}

Sample output