Hello everyone,
I am trying to write program that solves the Towers of Hanoi game using recursion. I am suppose to get the input from the user about how many discs, the start peg, and end peg.
The way I am trying to solve it now is by hard coding the values (3 discs, start from peg#1 and end on peg#3).
The problem I am having is outputting what peg to move it too. Can someone point me in the right direction?
Main function:
The outputCode:int main(int argc, char *argv[])
{
int start = 1;
int numDisk = 3;
int end = 3;
towersHanoi(numDisk, start, end);
return 0;
}
void towersHanoi(int disks, int start, int end)
{
if(disks>0)
{
towersHanoi(disks-1, start, end);
cout << "Move disk from " << start << " to " << end << endl;
towersHanoi(disks-1, start, end);
}
}
Thank you for the helpCode:[csc103]$ ./towers
Move disk from 1 to 3
Move disk from 1 to 3
Move disk from 1 to 3
Move disk from 1 to 3
Move disk from 1 to 3
Move disk from 1 to 3
Move disk from 1 to 3

