1. ## Total moves

Where and how would I add a part in my program that tells how many moves were done? here is my code:

#include<stdio.h>
void towers(int, int, int, int);

int level[3];
int main()
{
int n;
printf("Enter the number of disks on peg # 1: " );
fflush(stdout);
scanf("%d",&n);
printf("\n");
level[0] = n;
level[1] = 0;
level[2] = 0;
towers(1, 3, 2, n);
return 0;
}
void towers(int fromTower, int toTower, int auxTower, int n)
{
if (n==1)
{
printf("Move disk 1 from level %d of tower %d to level %d of tower %d\n",level[fromTower - 1],fromTower,level[toTower-1] + 1,toTower );
level[fromTower - 1] -= 1;
level[toTower - 1] += 1;
}
else
{
towers(fromTower, auxTower, toTower, n-1);
printf("Move disk %d from level %d of tower %d to level %d of tower %d\n",n,level[fromTower - 1],fromTower,level[toTower-1] + 1,toTower );
level[fromTower - 1] -= 1;
level[toTower - 1] += 1;
towers(auxTower, toTower, fromTower,
n-1);
}
}

2. You have made no effort to do that....
cmon ive done 3/4 of it for you already.

3. I tried figuring out how to print the total moves, I tried the following but it always says "Total moves: 1" no matter how many disks i enter.

#include<stdio.h>
int towers(int, int, int, int);

int level[3];
int main()
{
int n;
printf("Enter the number of disks on peg # 1: " );
fflush(stdout);
scanf("%d",&n);
printf("\n");
level[0] = n;
level[1] = 0;
level[2] = 0;

printf("Total moves: %d\n", towers(1, 3, 2, n));
return 0;
}
int towers(int fromTower, int toTower, int auxTower, int n)
{
int counter = 0;
if (n==1)
{
printf("Move disk 1 from level %d of tower %d to level %d of tower %d\n",level[f
romTower - 1],fromTower,level[toTower-1] + 1,toTower );
counter++;
level[fromTower - 1] -= 1;
level[toTower - 1] += 1;
}
else
{
towers(fromTower, auxTower, toTower, n-1);
printf("Move disk %d from level %d of tower %d to level %d of tower %d\n",n,leve
l[fromTower - 1],fromTower,level[toTower-1] + 1,toTower );
counter++;
level[fromTower - 1] -= 1;
level[toTower - 1] += 1;
towers(auxTower, toTower, fromTower, n-1);
return counter;
}
}

4. # of moves = (2^n) - 1