Calling function using input

Nov 18, 2010 at 2:08am
Hello guys,
I want to call a certain function based on an input of the user, for example
I declare a int Num;
then I have multiple versions of a function named Function1(), Function2(), ..FunctionN(),
Hence the user Inputs a number called Num ,
lets say the user inputs 3
Then I want to call Function3()

How can I do that ??
Nov 18, 2010 at 2:31am
1
2
3
4
5
6
7
8
if(Num==1)
function1();
else if(Num==2)
fucntion2();
.
.
.
.
Nov 18, 2010 at 2:53am
If the functions have the same prototype you could use an array of functions.
Last edited on Nov 18, 2010 at 2:54am
Nov 18, 2010 at 4:34am
if not, a switch/case would be easier on the eyes than an if/else if/else if... sequence.
Topic archived. No new replies allowed.