Good afternoon all. Here is a function that accepts an int data type for 'product' and selects the appropriate case. I need help with the 'default' option. If a user enters a bad value, I would like the default case to execute and allow the user to reenter a number option( suing cin>>product). Once the default option is executed, how do I get the program to return to the top of this function for cin>>product; and reselect the appropriate case?
Here's the code..................
int productSelection()
{
cin>>product; //User's menu choice, var declared
//in main()
if(product!=-1)
{ //begin TRUE path
switch(product)
{
case 1:
sandwich();
break;
case 2:
chips();
break;
case 3:
drink();
break;
case 4:
totalSale();
break;
default:
cout<<"You entered and incorrect option."<<endl;
cout<<"Please enter another option or enter"<<endl;
cout<<"-1 to end the program."<<endl;
break;
} //end of switch
} //end of TRUE path
else
{ main();} //returned to main for end
} //end of productSelection