basically i need to create a counter to count how many times the fxn is called recursively. Say like this:
Code:
int timer(int moves)//fxn to calculate # of moves
{
return moves++;
}
void Move(int n, char source, char destination, char spare,int moves)
{
timer(moves);//counts the number of times the fxn is called
if (n == 1)
{
cout << "Move the top disk from " << source
<< " to " << destination << endl;
cout << endl << moves << endl;
}
else
{
Move (n - 1, source, spare, destination,moves);
//timer(moves);//counts the number of times the fxn is called
Move (1, source, destination, spare,moves);
//timer(moves);//counts the number of times the fxn is called
Move (n - 1, spare, destination, source,moves);
//timer(moves);//counts the number of times the fxn is called
}
}
I tried putting the timer function everywhere... didn't work. The output was wrong.
I want it to print out :
Move the top disk from A to B
number of moves 1 total
Move the top disk from B to C
number of moves 2 total
.... and so on..