hey i was wondering if someone could help me with this problem. It deals with the hanoi puzzle and i did the code but the output isnt correct and ii cant figure out why can someone help?
heres my code
#include<iostream>
using namespace std;
void towers_of_hanoi(int height, int from, int to);
int main()
{
int num_of_pegs;
int peg1,peg2;
cout<<"How many pegs do you want to move? : ";
cin>> num_of_pegs;
cout<<" From which peg? :" <<endl;
cin>>peg1;
cout<<" To which peg? : "<<endl;
cin>>peg2;
towers_of_hanoi(num_of_pegs, peg1,peg2);
return 0;
}
void towers_of_hanoi(int height, int from, int to)
{
if(height==1)
cout<<"Move a disk from peg "<< from<< " to peg "<< to<<endl;
else
{
towers_of_hanoi(height - 1,from, to);
cout<<"Move a disk from peg "<< from<< " to peg "<< to<<endl;
towers_of_hanoi(height - 1,to,from);
}
}
and the output is supposed to look like this
SAMPLE OUTPUT
Output is supposed to look like this but it doesnt. What am i doing wrong/???
how many disks do you want to move? _3__
from which peg? __3_
to which peg? __2_
move a disk from peg 3 to peg 2.
move a disk from peg 3 to peg 1.
move a disk from peg 2 to peg 1.
move a disk from peg 3 to peg 2.
move a disk from peg 1 to peg 3.
move a disk from peg 1 to peg 1.
move a disk from peg 3 to peg 2.