There are many ways to collect user input. In this example a user is prompted to make a selection from a numbered list. This sets the int choice variable, which can then be used to control programme flow.
The possible values for user selection, along with a related string label for each value are set up using a struct.
Input is handled by std::getline(), with the input converted to an integer by means of the std::stringstream operator >>. I’ve done it this way rather than using std::cin so that an empty return can be handled and interpreted as the default value, if this has been set in the selectAction() function call.
Compile this using c++11 standards. for example: g++ -o test -std=c++11 test.cpp
I’m sure there are better ways to allow users to choose from a list of integer values - please leave a comment if you have a suggestion.