#include #include #include //for class string #include //for class map using namespace std; int main() { const map m { {"Bronx", 1406332}, {"Brooklyn", 2653963}, {"Manhattan", 1664862}, {"Queens", 2358182}, {"Staten Island", 495747} }; cout << "Please type a borough: "; string borough; getline(cin, borough); if (!cin) { cerr << "Sorry, couldn't read that.\n"; return EXIT_FAILURE; } const auto it {m.find(borough)}; int population; //can't be const if (it == end(m)) { population = 1000000; //borough not found: use a dummy number } else { population = it->second; //it->first would be the name } //Another way to do the same thing. This time, pop can be const. const int pop {it == end(m) ? 1000000 : it->second}; cout << population << "\n"; cout << pop << "\n"; return EXIT_SUCCESS; }