Yes, this is where I'd test the input. You could do it here (if you test the stream) or send a string to another function to validate it.
Code:
//example of stream validation. It isn't the most robust (the ignore condition could be more sophisticated), but will work under most conditions.
bool inputIsInvalid;
do
{
inputIsInvalid = true;
while(inputIsInvalid)
{
menu.MainMenu();
cout << endl << "Enter Option: " ;
cin >> input;
if(cin.fail)
{
cin.clear();
cin.ignore(3000);
cout << "invalid input. try again" << endl;
}
else
inputIsInvalid = false
}
cout << endl << endl ;
controlInput.CommandControl(input);
}while (input != 3);
Code:
//example of using a string for data/input validation
bool inputIsInvalid;
char input[80];
int length;
int i;
do
{
inputIsInvalid = true;
while(inputIsInvalid)
{
menu.MainMenu();
cout << endl << "Enter Option: " ;
cin >> input;
length = strlen(input);
if(length > 1)
cout << "input is invalid" << endl;
else if(!isdigit(input[0]))
cout << "input is invalid" << endl;
else
{
i = atoi(input);
inputIsInvalid = false;
}
cout << endl << endl ;
controlInput.CommandControl(i);
}while (i != 3);
In either case you have gauranteed that CommandControl will be passed an int. Then, in CommandControl you can use your switch statement to determine what to do. You might want to vailidate the size of the int before sending it to CommandControl since an int with value greater than 3 is invalid for the purposes of your program and you could ask for user to repeat input all in the same place.