3.19 LAB: Seasons In C++ 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. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June 20 Summer: June 21 - September 21 Autumn: September 22 - December 20 Winter: December 21 - March 19

Respuesta :

Answer:

#include <iostream>

#include <string>

using namespace std;

int main() {

  string mth;

int dy;

cin >> mth >> dy;

if ((mth == "January" && dy >= 1 && dy <= 31) || (mth == "February" && dy >= 1 && dy <= 29) || (mth == "March" && dy >= 1 && dy <= 19) || (mth == "December" && dy >= 21 && dy <= 30))

cout << "Winter" << endl;

else if ((mth == "April" && dy >= 1 && dy <= 30) || (mth == "May" && dy >= 1 && dy <= 30) || (mth == "March" && dy >= 20 && dy <= 31) || (mth == "June" && dy >= 1 && dy <= 20))

cout << "Spring" << endl;

else if ((mth == "July" && dy >= 1 && dy <= 31) || (mth == "August" && dy >= 1 && dy <= 31) || (mth == "June" && dy >= 21 && dy <= 30) || (mth == "September" && dy >= 1 && dy <= 21))

cout << "Summer" << endl;

else if ((mth == "October" && dy >= 1 && dy <= 31) || (mth == "November" && dy >= 1 && dy <= 30) || (mth == "September" && dy >= 22 && dy <= 30) || (mth == "December" && dy >= 0 && dy <= 20))

cout << "Autumn" << endl;

else

cout << "Invalid" << endl;

  return 0;

}

Explanation:

Answer: sorry this is in coral

integer inputMonth

integer inputDay

inputMonth = Get next input

inputDay = Get next input

if (inputMonth == 1 and inputDay >= 1 and inputDay <= 31)

Put "winter" to output

elseif (inputMonth == 2 and inputDay >= 1 and inputDay <= 29)

Put "winter" to output

elseif (inputMonth == 3)

if (inputDay >= 1 and inputDay <= 19)

Put "winter" to output

elseif (inputDay > 19 and inputDay <= 31)

Put "spring" to output

elseif (inputDay >=32)

Put "invalid" to output

elseif (inputMonth == 4 and inputDay >=1 and inputDay <= 30)

Put "spring" to output

elseif (inputMonth == 5 and inputDay >=1 and inputDay <= 31)

Put "spring" to output

elseif (inputMonth == 6)

if (inputDay >=1 and inputDay <= 20)

Put "spring" to output

elseif (inputDay >= 21 and inputDay <= 30)

Put "summer" to output

elseif (inputDay >=31)

Put "invalid" to output

elseif (inputMonth == 7 and inputDay >=1 and inputDay <= 31)

Put "summer" to output

elseif (inputMonth == 8 and inputDay >=1 and inputDay <= 30)

Put "summer" to output

elseif (inputMonth == 9)

if (inputDay >=1 and inputDay <=21)

Put "summer" to output

elseif (inputDay >= 22 and inputDay <=30)

Put "autumn" to output

elseif (inputDay >=31)

Put "invalid" to output

elseif (inputMonth == 10 and inputDay >=1 and inputDay <= 31)

Put "autumn" to output

elseif (inputMonth == 11 and inputDay >=1 and inputDay <= 30)

Put "autumn" to output

elseif (inputMonth == 12)

if (inputDay <= 0)

Put "invalid" to output

elseif (inputDay >= 1 and inputDay <= 20)

Put "autumn" to output

elseif (inputDay >=21 and inputDay<=31)

Put"winter" to output

else

Put "invalid" to output

Explanation:

ACCESS MORE
EDU ACCESS