我无法理解我收到的这个错误。这个任务的目的是创建一个程序,打印出13个学校团队,他们的记录,然后打印出胜率超过.500的团队。尝试处理wins_teams函数时,我的main函数内部会发生错误。
exit status 1
/tmp/ccSw87Of.o: In function `main':
main.cpp:(.text+0x8ea): undefined reference to `winning_teams(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, double, double)'
collect2: error: ld returned 1 exit status
这是我的代码!如果可以,请帮助
#include <iostream>
#include<string>
using namespace std;
struct Team
{
string name;
int wins;
int losses;
};
double win_percentage (string , double , double );
void wins_losses (string , double , double , double );
void winning_teams (string , double , double , double );
int main(){
int const NUM = 13;
Team school[NUM]= {
{"Bethune-Cookman", 11, 3}, {"Coppin State", 5, 9}, {"Delaware State", 1, 13},{"Florida A&M", 6, 8},{"Hampton", 11, 4},{"Howard", 6, 8},{"Maryland Eastern Shore", 2, 12},{"Morgan State", 6, 8},{"North Carolina A&T", 10, 4}, {"North Carolina Central", 8, 6},{"Norfolk State", 10, 4},{"Savannah State", 10, 4},{"South Carolina State", 6, 8}};
cout<< "MEAC MENS BASKETBALL TEAMS CONFERENCE STANDINGS"<< endl;
for (int i = 0; i<NUM; i++){
cout<< school[i].name<<" "<<school[i].wins<<"-"<<school[i].losses<< endl;
cout<<"TEAMS WINNING PERCENTAGE"<<endl;
win_percentage(school[i].name,school[i].wins,school[i].losses);
cout<<"TEAMS WITH WINNING RECORDS"<<endl;
wins_losses(school[i].name,school[i].wins,school[i].losses, win_percentage(school[i].name,school[i].wins,school[i].losses));
winning_teams(school[i].name,school[i].wins,school[i].losses,win_percentage(school[i].name,school[i].wins,school[i].losses));
}
return 0;
}
double win_percentage(string a, double b, double c){
double x;
x = (b/(b+c));
return x;
cout<< a<<" "<<x<<endl;
}
void wins_losses( string e, double f, double g, double h){
cout<< e<< "Record is"<<f<<"-"<<g<< h<<endl;
}
void winning_teams(string w, int f, int y, double z){
if ( z >.500){
cout<< w<<" "<<f<< "-"<<y<< " "<< z<< endl;
}
}
答案 0 :(得分:2)
在你的wins_teams声明中,函数参数列表是string,double,double,double!但是在你的定义中,它是不同的,即string,int,int,double!
由于函数定义不匹配,它会抛出错误!
可能的解决方案:
void winning_teams(string w, double f, double y, double z){
if ( z >.500){
cout<< w<<" "<<f<< "-"<<y<< " "<< z<< endl;}