i wrote a code to validate my input
int id;
cout <<"Enter Your ID: "; cin>>id;
while (cin.fail())
{
cout << "\" This is not a valid option please try again: ";
cin >> id;
if (cin.fail())
{
cin.clear();
string input;
cin >> input;
cout << "\n\t\"" << input << "\" This is not a vaild option please try again: ";
cin >> id;
}
}
so this works but what i want to make a function out of this but the problem is that what data type would i pass in the parameter because the above code could be used for string , ints or chars as well but how do i put that code in a function: is this even possible?
void validation()
{
while (cin.fail())
{
cout << "\" This is not a vaild option please try again: ";
cin >> id;
if (cin.fail())
{
cin.clear();
string input;
cin >> input;
cout << "\n\t\"" << input << "\" This is not a vaild option please try again: ";
cin >> id;
}
}
}