I have recently made a menu through a do/while loop to perform a set of actions. The menu appears in the terminal and lets me make a selection without any problems. However, when I finally make my choice, the functions never seem to be called. This results in being returned to the main part of the menu with no action undertaken. I have attached a smaller code snippet below as an example:
void Menu()
{
std::cout<<"-----------------------------------------------------"<<std::endl;
std::cout<<"\t \t Welcome. \t \t"<<std::endl;
std::cout<<"-----------------------------------------------------"<<std::endl;
std::cout<<"1. Input Data for objects (Person, Dependent, Employeem Manager, Worker)."<<std::endl;
std::cout<<"2. Inquire values."<<std::endl;
std::cout<<"3. Replace values."<<std::endl;
std::cout<<"4. Quit.";
std::cout<<"Enter your choice and press return."<<std::endl;
}
int main(void)
{
Person P;
Dependent D;
Employee E;
Manager M;
Worker W;
Menu();
int user_input;
char answer;
do
{
std::cout<<"Select an option"<<std::endl;
std::cin>>user_input;
switch (user_input)
{
case 1:
{
std::string choice;
std::cout<<"Pick an object type (P/p, D/d, E/e, M/m, or W/w)"<<std::endl;
std::getline(std::cin, choice);
if (choice == "P" || choice == "p")
{
P.create_data();
}
}
}
std::cout<<"Press anything but 4 to continue"<<std::endl;
std::cin>>answer;
}
while (answer != 4);
}
Also, here is the function being called:
void Person::create_data()
{
std::cout<<"Name: ";
std::cin>>name;
std::cout<<"Date of Birth: ";
std::cin>>date_of_birth;
std::cout<<"Gender: ";
std::cin>>gender;
std::cout<<"SSN: ";
std::cin>>SSN;
std::cout<<"Address: ";
std::cin>>address;
std::cout<<"Home Phone: ";
std::cin>>home_phone_number;
}
Thanks.