I have been able to figure out how to manipulate and use information in vectors, but would now like to use the following code to make a question menu based on the two questions I ask. How would you make a switch case menu?
Thanks!
Do you know about functions? Do you know about passing parameters by reference?
Otherwise I’m afraid your switch-based menu would probably became a mess.
#include <iostream>
#include <string>
int main()
{
std::string again;
do {
int option;
do {
std::cout << "What do you want to do?\n1) Add a name\n""2) Delete a name\n\n"">>> ";
std::cin >> option;
switch (option) {
case 1:
// your code here (it's better to call a function)
break;
case 2:
// your code here (it's better to call a function)
break;
default:
std::cout << "Can't understand your choice. Please try again.\n";
continue;
}
} while (option < 1 || 2 < option);
std::cout << "Would you like to continue (Y/N)? ";
std::cin >> again;
again = toupper(again.at(0));
} while(!again.compare("Y"));
return 0;
}