userInteraction.hpp
template <typename T1, typename T2>
void RequestInput(const string message, T1& input, const T2 min, const T2 max)
{
bool valid_input; // for checking if the input is in range
do // do at least once
{
cout << message; // output the message to the console
cin >> input; // read in value from the console
valid_input = CheckRange(input, min, max); // check if input is in range
if (!valid_input) // if the input is no good
cout << "Invalid input. Try again." << endl; // they need to try again
} while (!valid_input); // while the input is not valid
return;
}
template <typename T1, typename T2>
void OutputAnswer(const long type, const T1 input, const T2 answer)
{
// each menu type has a defined format for its answer
switch (type)
{
case MENU_FACT:
{
cout << "Factorial of " << input << " is " << answer << endl;
break;
}
case MENU_EXP:
{
cout << "e to the power " << input << " is " << answer << endl;
break;
}
case MENU_SIN:
{
cout << "Sine(" << input << ") is " << answer << endl;
break;
}
case MENU_ROOT:
{
cout << "The root of " << input << " is " << answer << endl;
break;
}
case MENU_COSH:
{
cout << "Hyperbolic cosine of " << input << " is " << answer << endl;
break;
}
case MENU_QUIT:
{
cout << "Bye, quitter." << endl;
break;
}
}
return;
}
template <typename T1, typename T2>
void RequestInput(const string message, T1& input, const T2 min)
{
bool valid_input; // for if the input is valid
do // do at least once
{
cout << message; // output message to console
cin >> input; // read in output from the console
valid_input = CheckRange(input, min); // check if input is at least min
if (!valid_input) // if the input is not valid
cout << "Invalid input. Try again." << endl; // tell them to try again
} while (!valid_input); // while the input is not valid
return;
}
template <typename T>
void RequestInput(const string message, T& input)
{
cout << message; // output message to the console
cin >> input; // read input from console
}