Write a method called input that type traps (and error traps) a user's integer input between two range values that are passed as parameters. The function should then return the value entered by the user.
b. Overload this function so that it takes double parameters.
c. Overload this function so that it does not have a range requirement (Allows the user to enter any integer number).
here is the code for the exception handling fucntion but I have no clue how to overload this function. Please help
int errorTrap(int MIN, int MAX)
{
int number;
do
{
if ( !cin.good() )
{
cout << "Error" << endl;
cin.clear ();
cin.ignore( 128, '\n' );
}
cout << "Enter a value:";
cin >> number;
if (number < MIN || number > MAX)
cout << "invalid entry\n";
}while(!cin.good() || number > MAX || number < MIN );
return number;
}
Function overloading is easy, you just make another function with the same name, but something about the definition changes (eg the return type, the # of parameters, and/or the types of the parameters)
All you have to do is make two more functions called errorTrap just like the existing one, but change the definition and code a bit.