Since both of them are independent of each other, you need to separate the into two functions for your purpose : validateChoice
which consists of the first while loop and validateMonths
which consists of second while loop.
If you want single function itself you need to pass appropriate parameter
int validate(int value, int lowLimit, int HighLimit)
{
while(value < lowLimit || value > HighLimit)
{
//print error message here
cin>> value;
}
return value;
}
In main, do
cin >> choice;
choice = validate(choice, 1, 4);
Similarly for months
.