#include #include #include using namespace std; int main() { //Each state is a structure holding a name and a number: struct state { string name; int income; //2021 median household income }; state a[] = { //an array of 50 structures {"Maryland", 90203}, {"Massachusetts", 89645}, {"New Jersey", 89296}, {"New Hampshire", 88465}, {"California", 84907}, {"Hawaii", 84857}, {"Washington", 84247}, {"Connecticut", 83771}, {"Colorado", 82254}, {"Virginia", 80963}, {"Utah", 79449}, {"Alaska", 77845}, {"Minnesota", 77720}, {"New York", 74314}, {"Rhode Island", 74008}, {"Vermont", 72431}, {"Illinois", 72205}, {"Oregon", 71562}, {"Delaware", 71091}, {"Arizona", 69056}, {"Pennsylvania", 68957}, {"Wisconsin", 67125}, {"Texas", 66962}, {"Nebraska", 66817}, {"Georgia", 66559}, {"North Dakota", 66519}, {"Idaho", 66474}, {"Nevada", 66274}, {"South Dakota", 66143}, {"Iowa", 65600}, {"Wyoming", 65204}, {"Maine", 64767}, {"Kansas", 64124}, {"Michigan", 63498}, {"Montana", 63249}, {"Florida", 63062}, {"Indiana", 62743}, {"Ohio", 62262}, {"North Carolina", 61972}, {"Missouri", 61847}, {"Tennessee", 59695}, {"South Carolina", 59318}, {"Oklahoma", 55826}, {"Kentucky", 55573}, {"New Mexico", 53992}, {"Alabama", 53913}, {"Arkansas", 52528}, {"Louisiana", 52087}, {"West Virginia", 51248}, {"Mississippi", 48716} }; int n {size(a)}; //the number of elements in the array cout << "Please type a state: "; string statename; getline(cin, statename); //Read whole line (might be more than 1 word) if (!cin) { cerr << "Sorry, couldn't receive input.\n"; return EXIT_FAILURE; } for (int i {0}; i < n; ++i) { if (a[i].name == statename) { //Found the statename! cout << a[i].name << " has 2021 median household income $" << a[i].income << "\n" << "That's " << i+1 << " out of " << n << ".\n"; return EXIT_SUCCESS; } } cerr << "Sorry, couldn't find state '" << statename << "'.\n"; return EXIT_FAILURE; }