I am making a function that takes a number from the user\'s input and finds the absolute value of it. I want to make it return an error if the user inputs anything other than j
Pass your number as a reference and return an error code. Using the function argument as an output parameter.
bool parseNumber(int &n)
{
...
//assign to number to n
// if number parsing is ok return true;
...
return false;
}
int main()
{
int number=0;
if(!parseNumber(number))
std::cout << "Number parsing failed\n";
}