Question: How should I change the code so that getUserOption receives strings such as help, help average as input instead of integers like 0, 1? int
How should I change the code so that getUserOption receives strings such as "help", help average" as input instead of integers like 0, 1?
int MerkelMain::getUserOption() { int userOption = 0; std::string line; std::cout << "Type in 1-6" << std::endl; std::getline(std::cin, line); try{ userOption = std::stoi(line); }catch(const std::exception& e) { // } std::cout << "You chose: " << userOption << std::endl; return userOption; }
void MerkelMain::processUserOption(int userOption)
{
if (userOption == 0) // bad input
{
std::cout << "Invalid choice. Choose 1-6" << std::endl;
}
if (userOption == 1)
{
printHelp();
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
