I currently use three different functions to return a numeric value (one returns a double
, the other two return a long
):
int main(void)
{
// lots of code
dRate = funcGetInterestRate();
lMonths = funcGetTerm();
lPrincipal = funcGetPrincipal();
// lots of code
return 0;
}
The three functions code is about 90% the same so I would like to consolidate into 1 function. I want to pass a value flag to a single function something like this:
- if "1" passed, determine interest rate, return a
double
- if "2" passed, determine term of loan, return a
long
- if "3" passed, determine principal of loan, return a
long
I only want to return 1 value ever from the function when it is called, but the value I want to return can be either a double
or a long
. I want to do something like this:
void funcFunction(value passed to determine either long or double)
{
// lots of code
if (foo)
return double value;
else
return long value;
}
Is there an easy way to do this?