137k views
5 votes
Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day.

User Venemo
by
3.6k points

1 Answer

7 votes

Answer:

void season(char * month, int day){

if(strcpy(month, "January") == 0 || strcpy(month, "February") == 0)

printf("Winter\\");

else if(strcpy(month, "March") == 0){

if(day < 20)

printf("Winter\\");

else

printf("Spring\\");

}

else if(strcpy(month, "April") == 0 || strcpy(month, "May") == 0)

printf("Spring\\");

else if(strcpy(month, "June") == 0){

if(day < 20)

printf("Spring\\");

else

printf("Summer\\");

}

else if(strcpy(month, "July") == 0 || strcpy(month, "August") == 0)

printf("Summer\\");

else if(strcpy(month, "September") == 0){

if(day < 20)

printf("Summer\\");

else

printf("Autumn\\");

}

else if(strcpy(month, "October") == 0 || strcpy(month, "November") == 0)

printf("Autumn\\");

else if(strcpy(month, "December") == 0){

if(day < 20)

printf("Autumn\\");

else

printf("Winter\\");

}

}

Step-by-step explanation:

I am going to write a C program for this.

I am going to use the function strcpy, from the library string.h, to compare strings. It returns 0 when strings are equal.

I am going to say that the season change happens at day 20, in March, June, September and December

void season(char * month, int day){

if(strcpy(month, "January") == 0 || strcpy(month, "February") == 0)

printf("Winter\\");

else if(strcpy(month, "March") == 0){

if(day < 20)

printf("Winter\\");

else

printf("Spring\\");

}

else if(strcpy(month, "April") == 0 || strcpy(month, "May") == 0)

printf("Spring\\");

else if(strcpy(month, "June") == 0){

if(day < 20)

printf("Spring\\");

else

printf("Summer\\");

}

else if(strcpy(month, "July") == 0 || strcpy(month, "August") == 0)

printf("Summer\\");

else if(strcpy(month, "September") == 0){

if(day < 20)

printf("Summer\\");

else

printf("Autumn\\");

}

else if(strcpy(month, "October") == 0 || strcpy(month, "November") == 0)

printf("Autumn\\");

else if(strcpy(month, "December") == 0){

if(day < 20)

printf("Autumn\\");

else

printf("Winter\\");

}

}

User Aaditya Maheshwari
by
3.6k points