First , if the compiler throws an error , it doesnt mean you have to check each & every line of the errors.
The compiler is just showing you what all options it evaluated before flagging the code as error.Compiler tries its best to make your code work by typecasting the types implicitly if we have not given a explicit method to do so.
The input suggested in the problem statement doesnt match the logic in your code,so I modifed it a bit.If both the user inputs are ints , just changing "string inputMonth;" to "int inputMonth;" will make your code working .
The problem with your code is you're trying to comparing equaltiy of strings(inputMonth) & int (12,9,3,6 from ur code)
no match for ‘operator==’ (operand types are ‘std::string’ {aka‘std::__cxx11::basic_string<char>’} and ‘int’)
So, now the error by compiler hopefully makes sense
string inputMonth;
..... // other lines of ur code
if (inputMonth == 12 && .... // other of ur code
Compiler tried to implicitly typecast string to int ,which is shown in the error messages.When it cant find a suitable candidate, your code is flagged as error.
//FIX:
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
string inputMonth;
std::map<string,int > string2int_month_map = {
{"January",1},
{"Feb",2},
{"Mar",3},
//... other months .. too lazy to populate the map, bailing out
{"Dec",12}
} ;
int inputDay;
cin >> inputMonth;
cin >> inputDay;
if (string2int_month_map[inputMonth] == 12 && inputDay >= 21) {
cout << "Winter" << endl;
}
if (string2int_month_map[inputMonth] == 12 && inputDay >= 21) {
cout << "Winter" << endl;
}
else if (string2int_month_map[inputMonth] <= 3 && inputDay <= 19) {
cout << "Winter" << endl;
}
#if 0 // block commented ,to stop compile error
else if (inputMonth >= 3 || inputMonth <= 6 && inputDay >= 20) {
cout << "Spring" << endl;
}
else if (inputMonth >= 6 || inputMonth <= 9 && inputDay >= 21) {
cout << "Autumn" << endl;
}
else if (inputMonth >= 9 && inputDay >= 22 || inputMonth == 12 && inputDay <= 20) {
cout << "Winter" << endl;
}
else {
cout << "Invalid" << endl;
}
#endif
return 0;
}
/*
Output
Mar
10
Winter
*/