#include #include #include #include //for the algorithm find_if using namespace std; struct month { string name; int games; }; int main() { const month a[] { {"January", 0}, {"February", 0}, {"March", 5}, {"April", 26}, {"May", 29}, {"June", 27}, {"July", 25}, {"August", 27}, {"September", 23}, {"October", 0}, {"November", 0}, {"December", 0} }; string usermonth; cout << "What month are you interested in " << "(start with an uppercase letter)?\n"; cin >> usermonth; if (!cin) { cerr << "Sorry, I couldn't read that.\n"; return EXIT_FAILURE; } const auto it {find_if(begin(a), end(a), [&usermonth](const month& m) {return m.name == usermonth;})}; if (it == end(a)) { //Searched all the way to the end of a without finding usermonth cerr << "Sorry, couldn't find \"" << usermonth << "\".\n"; return EXIT_FAILURE; } cout << "In " << it->name << ", the Yankees play " << it->games << " game(s).\n"; return EXIT_SUCCESS; }