Here is the problem. I am using a switch and I want the user to pick a number (1-6), and if he enters a letter or any other character then it will go to the default and tell them they entered the wrong choice and to chose again which will run the function that allows them to pick again. I have all of that working, but my problem is when I call the function in the default it gets stuck in a loop because the value in the varaiable that caused the loop is still in there. Can someone help and get me out this loop.
Thanks
Here is the code I have:
#include<iostream.h>
class finalswitch
{
private:
int value;
public:
void set();
void newcode();
};
void finalswitch::set ()
{
cout<<"Enter a value"<<endl;
cin>>value;
switch(value)
{
case 1:
cout<<"This is 1";
break;
case 2:
cout<<"This is 2";
break;
case 3:
cout<<"This is 3";
break;
case 4:
cout<<"This is 4";
break;
case 5:
cout<<"This is 5";
break;
case 6:
cout<<"This is 6";
break;
default:
set();
}
}
void main()
{
finalswitch aswitch;
aswitch.set ();
}