#include #include #include using namespace std; int main() { const size_t NUM_FACTS_PER_STATE {4}; const size_t STATE_NAME {0}; const size_t CAPITAL {1}; const size_t NICKNAME {2}; const size_t FLOWER {3}; const string stateFacts[][NUM_FACTS_PER_STATE] { // Name Capital Nickname Flower {"New York", "Albany", "The Empire State", "Rose"}, // [0] {"California", "Sacramento", "The Golden State", "Poppy"}, // [1] {"Texas", "Austin", "The Lone Star State", "Bluebonnet"}, // [2] {"Florida", "Tallahassee", "The Sunshine State", "Orange Blossom"}, // [3] {"Illinois", "Springfield", "Land of Lincoln", "Violet"} // [4] }; const size_t NUM_STATES {size(stateFacts)}; const size_t NUM_FACTS_TO_LOOK_UP {3}; cout << "Choose a State to look up by picking a number between 0 and " << NUM_STATES - 1 << " inclusive:\n"; for (size_t i = 0; i < NUM_STATES; ++i) { cout << "\t" << i << ": " << stateFacts[i][STATE_NAME] << "\n"; } int state_index {0}; cin >> state_index; if (!cin) { cerr << "Sorry, unable to receive an integer.\n"; return EXIT_FAILURE; } if (state_index < 0 || state_index >= NUM_STATES) { cerr << "Invalid state index. Must be 0 to " << NUM_STATES - 1 << ".\n"; return EXIT_FAILURE; } cout << "What fact do you want (0-2)?\n" << "\t0: Capital\n" << "\t1: Nickname\n" << "\t2: State Flower\n"; int fact_index {0}; cin >> fact_index; if (fact_index < 0 || fact_index >= NUM_FACTS_TO_LOOK_UP) { cerr << "Invalid fact index. Must be 0 to " << NUM_FACTS_TO_LOOK_UP - 1 << ".\n"; return EXIT_FAILURE; } size_t actual_array_index = fact_index + 1; cout << stateFacts[state_index][actual_array_index] << "\n"; return EXIT_SUCCESS; }