i've been making simple programs for practice. i am stuck on something easy lol. I made a simple program with a switch statement asking to add delete and edit persons info. i've successfully made a switch statement but how do i make it a loop if the user types in an option outside the scope of the switch statement. do i use a while loop and put the switch inside it or can i use something within the switch statement until user correctly types correctly? i would like to have this program in continous loop until the user exits program. and oh yeah is default necessary for switch statement? thank you
instead of while i used do while loop and it worked but i would like to put limits between 1 to 5 and i tried doing in while paranthesis but doesnt do anything this is what i have below
do
{
cout <<"This program lets you add up to 3 employees for your records."<<endl;
cout <<"You have 3 options."<<endl;
cout <<"Option 1 is to add employee, option 2 to display employee option 3 to edit"<<endl;
cout <<"employee and option 4 to delete employee."<<endl;
cin >>option;
switch (option)
{
case 1:
cout <<"Add employee"<<endl;
break;
case 2:
cout <<"display employee"<<endl;
break;
case 3:
cout <<"edit employee"<<endl;
break;
case 4:
cout <<"delete employee"<<endl;
break;
default:
cout <<"You are done. Have a nice day."<<endl;
break;
}
}
while (option > 0 && option <5);