哪位好心的大神帮我看看程序那个地方出错了
#include<iostream>
using namespace std;
const int Len=40;
struct golf{
char fullname[Len];
int handicap;
};
void setgolf(golf& g,char* name,int hc);
void handicap(golf& g,int hc):
void show(const golf& g);
int main(){
golf no1={"wangxu",123};
show(no1);
cout<<"please input another one"<<endl;
golf no2;
int Handicap;
char Fullname[Len];
cin>>Handicap;
cin.getline(Fullname,Len);
setgolf(g,Fullname,Handicap);
show(no2);
cout<<"input no3: \n";
golf no3;
setgolf(no3);
cout<<"no3:\n";
show(no3);
cout<<"change handicap\n";
cin>>Handicap;
setgolf(no3,Handicap);
show(no3);
cout<<"Bye-bye!\n";
return 0;
}
void setgolf(golf& g,const char*name,int hc){
strcpy(g.fullname,name);
g.handicap=hc;
}
int setgolf(golf& g){
cout<<"please input the name: ";
cin.getline(g.fullname,Len);
cout<<"please input the handicap: ";
cin>>g.handicap;
if(g.fullname='\0')
return 0;
else
return 1;
}
void show(const golf& g){
cout<<g.fullname<<endl;
cout<<g.handicap<<endl;
}
void handicap(golf& g,int hc){
g.handicap=hc;
}
[解决办法]
#include <iostream> //没有添加头文件
using namespace std;
const int Len=40;
struct golf{
char fullname[Len];
int handicap;
};
void setgolf(golf& g,char* name,int hc);
void handicap(golf& g,int hc);
void show(const golf& g);
int main(){
golf no1={"wangxu",123};
show(no1);
cout<<"please input another one"<<endl;
golf no2;
int Handicap;
char Fullname[Len];
cin>>Handicap;
cin.getline(Fullname,Len);
setgolf(no2,Fullname,Handicap); //形参和实参没有区分出来,g没有定义,看你的意思应该是no2
show(no2);
cout<<"input no3: \n";
golf no3;
setgolf(no3);
cout<<"no3:\n";
show(no3);
cout<<"change handicap\n";
cin>>Handicap;
setgolf(no3,Fullname,Handicap);//setgolf(no3,Handicap); 这里函数的调用与原型不符,我按照上下文改了
show(no3);
cout<<"Bye-bye!\n";
return 0;
}
void setgolf(golf& g,const char*name,int hc){
strcpy(g.fullname,name);
g.handicap=hc;
}
int setgolf(golf& g){
cout<<"please input the name: ";
cin.getline(g.fullname,Len);
cout<<"please input the handicap: ";
cin>>g.handicap;
if(g.fullname=='\0')
return 0;
else
return 1;
}
void show(const golf& g){
cout<<g.fullname<<endl;
cout<<g.handicap<<endl;
}
void handicap(golf& g,int hc){
g.handicap=hc;
}
看看跟你的初衷一样吗
[解决办法]
const int Len=40;
struct golf{
char fullname[Len];
int handicap;
};
void setgolf(golf& g,const char* name ="",int hc = 0);
void handicap(golf& g,int hc);
void show(const golf& g);
int main(){
golf no1={"wangxu",123};
show(no1);
cout<<"please input another one"<<endl;
golf no2;
int Handicap;
char Fullname[Len];
cin>>Handicap;
cin.getline(Fullname,Len);
setgolf(no2,Fullname,Handicap);//
show(no2);
cout<<"input no3: \n";
golf no3;
setgolf(no3);
cout<<"no3:\n";
show(no3);
cout<<"change handicap\n";
cin>>Handicap;
setgolf(no3);
show(no3);
cout<<"Bye-bye!\n";
return 0;
}
void setgolf(golf& g,const char*name,int hc){
strcpy(g.fullname,name);
g.handicap=hc;
}
int setgolf(golf& g){
cout<<"please input the name: ";
cin.getline(g.fullname,Len);
cout<<"please input the handicap: ";
cin>>g.handicap;
if(g.fullname[0]='\0')
return 0;
else
return 1;
}
void show(const golf& g){
cout<<g.fullname<<endl;
cout<<g.handicap<<endl;
}
void handicap(golf& g,int hc){
g.handicap=hc;
}