求助
#include<iostream>using namespace std;
void move();
void hanoi(int n,char src,char medium,char dest)
{
if(n==1)
void move(char src,char dest);
else
{ hanoi(n-1,src,dest,medium);
move(src,dest);
hanoi(n-1,medium,src,dest);
}
}
void move(char src,char dest)
{
cout<<src<<"--→"<<dest<<endl;
}
int main()
{
int m;
cout<<"enter the number of diskes:"<<endl;
cin>>m;
cout<<"the steps to moving"<<m<<"diskes:"<<endl;
hanoi(m,'A','B','C');
return 0;
}error C2660: “move”: 函数不接受 2 个参数 哪里出错了? 你可能还要继续练习一下函数的使用。。
#include<iostream>
using namespace std;
//void move();
void move(char src,char dest);
void hanoi(int n,char src,char medium,char dest)
{
if(n==1)
//void move(char src,char dest);
move(src,dest);
else
{ hanoi(n-1,src,dest,medium);
move(src,dest);
hanoi(n-1,medium,src,dest);
}
}
void move(char src,char dest)
{
cout<<src<<"--→"<<dest<<endl;
}
int main()
{
int m;
cout<<"enter the number of diskes:"<<endl;
cin>>m;
cout<<"the steps to moving"<<m<<"diskes:"<<endl;
hanoi(m,'A','B','C');
return 0;
}
页:
[1]