#include #include #include "ranks.h" using namespace std; int main() { const branch b[] = { //an array of six objects branch {0}, //Navy branch {1}, //Army branch {2}, //Marines branch {3}, //Air Force branch {4}, //Space Forces branch {5} //Coast Guard }; const size_t n {size(b)}; //the number of branches cout << "Choose a branch:\n"; for (int i {0}; i < n; ++i) { cout << i + 1 << ". " << b[i].getName() << "\n"; } cout << "\n"; int choice {0}; cout << "Enter the number of your choice: "; cin >> choice; if (!cin) { cerr << "Sorry, couldn't read that.\n"; return EXIT_FAILURE; } if (choice < 1 || choice > n) { cerr << "Sorry, choice must be in range 1 to " << n << " inclusive.\n"; return EXIT_FAILURE; } b[choice - 1].print(); return EXIT_SUCCESS; }