Question: How should I change the code so that getUserOption receives strings such as help, help average as input instead of integers like 1, 2, 3?
How should I change the code so that getUserOption receives strings such as "help", help average" as input instead of integers like 1, 2, 3?
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; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
