#include void menu_item_0(void) { std::cout << "You chose menu item 0." << std::endl; std::cout << "If this menu actually worked, something would be done here." << std::endl; } void menu_item_1(void) { std::cout << "You chose menu item 1." << std::endl; std::cout << "If this menu actually worked, something would be done here." << std::endl; } void menu_item_2(void) { std::cout << "You chose menu item 2." << std::endl; std::cout << "If this menu actually worked, something would be done here." << std::endl; } void menu_item_3(void) { std::cout << "You chose menu item 3." << std::endl; std::cout << "If this menu actually worked, something would be done here." << std::endl; } void menu_item_4(void) { std::cout << "You chose menu item 4." << std::endl; std::cout << "If this menu actually worked, something would be done here." << std::endl; } void menu_item_5(void) { std::cout << "You chose menu item 5." << std::endl; std::cout << "If this menu actually worked, something would be done here." << std::endl; } void show_menu(void) { std::cout << std::endl; std::cout << "SIMPLE MENU" << std::endl; std::cout << "-----------" << std::endl; std::cout << std::endl; std::cout << "0. Menu item 0" << std::endl; std::cout << "1. Menu item 1" << std::endl; std::cout << "2. Menu item 2" << std::endl; std::cout << "3. Menu item 3" << std::endl; std::cout << "4. Menu item 4" << std::endl; std::cout << "5. Menu item 5" << std::endl; std::cout << std::endl; std::cout << "Enter your selection (ctrl-d to quit): " << std::flush; } typedef void (*menu_function)(void); menu_function functions[] = {menu_item_0, menu_item_1, menu_item_2, menu_item_3, menu_item_4, menu_item_5}; // The above 2 lines can be done in the following single line, but this // line is quite hard to understand, so the typedef is better. //void (*functions[])(void) = {menu_item_0, menu_item_1, menu_item_2, menu_item_3, menu_item_4, menu_item_5}; int main() { int choice; show_menu(); while (std::cin >> choice) { if (choice < 0 || choice > 5) { std::cout << "Invalid input, enter a number between 0 and 5" << std::endl; } else { functions[choice](); } show_menu(); } std::cout << std::endl; }