In: Computer Science
** IN C++ **
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
My code isn't working and I can't figure out why please help.
#include <iostream>
#include <string>
using namespace std;
int main() {
string inputMonth;
int inputDay;
cin >> inputMonth;
cin >> inputDay;
if (inputMonth = "March") && (inputDay > 19) &&
(inputDay < 32) {
cout << "Spring" << endl;
}
else if (inputMonth = "April" && inputDay > 0 &&
inputDay < 31) {
cout << "Spring" << endl;
}
else if (inputMonth = "May" && inputDay > 0 &&
inputDay < 32) {
cout << "Spring" << endl;
}
else if (inputMonth = "June" && inputDay > 0 &&
inputDay < 21) {
cout << "Spring" << endl;
}
else if (inputMonth = "June" && inputDay > 20 &&
inputDay < 31) {
cout << "Summer" << endl;
}
else if (inputMonth = "July" && inputDay > 0 &&
inputDay < 32) {
cout << "Summer" << endl;
}
else if (inputMonth = "August" && inputDay > 0
&& inputDay < 32) {
cout << "Summer" << endl;
}
else if (inputMonth = "September" && inputDay > 0
&& inputDay < 23) {
cout << "Summer" << endl;
}
else if (inputMonth = "September" && inputDay > 24
&& inputDay < 31) {
cout << "Autumn" << endl;
}
else if (inputMonth = "October" && inputDay > 0
&& inputDay < 32) {
cout << "Autumn" << endl;
}
else if (inputMonth = "November" && inputDay > 0
&& inputDay < 31) {
cout << "Autumn" << endl;
}
else if (inputMonth = "December" && inputDay > 0
&& inputDay < 22) {
cout << "Autumn" << endl;
}
else if (inputMonth = "December" && inputDay > 23
&& inputDay < 32) {
cout << "Winter" << endl;
}
else if (inputMonth = "January" && inputDay > 0
&& inputDay < 32) {
cout << "Winter" << endl;
}
else if (inputMonth = "February" && inputDay > 0
&& inputDay < 29) {
cout << "Winter" << endl;
}
else if (inputMonth = "March" && inputDay > 0 &&
inputDay < 20) {
cout << "Winter" << endl;
}
else {
cout << "Invalid" << endl;
}
return 0;
}
Answer-
Your code is given below-
Screenshot of some sample output-
Note- Please do upvote, if any problem then comment in
box sure I will help.