Its not legal. You are declaring "value" twice in their own statement blocks and don't have scope within main(). For example, the following is equivalent:
Code:
int main()
{
int random;
if (random > 3)
{
int value; //can't access value outside of {}
}
if (random <= 3)
{
float value;
}
add_factor(value); //value not defined in this scope
return 0; //added for correctness
}
Your function declarations for add_factor() are ok. The type of the parameter will determine which function is called.
You can accomplish what [it looks like] you were thinking like this:
Code:
if (random > 3)
add_factor(<something of int type>);
if (random <= 3)
add_factor(<something of float type>);
You can use templates and template specialization to do something similiar.
gg