gpt4 book ai didi

c++ - 未解析的外部符号,在函数 _main 中引用

转载 作者:行者123 更新时间:2023-11-27 23:19:59 26 4
gpt4 key购买 nike

<分区>

    #include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const int numplayers = 10;
const int numscores = 3;

void playerNames(string[],int);
void batsHits(int[][numscores],double[][numscores],int, int,string[]);
void battingAverage(int[][numscores],double[][numscores],int,int);
void displayStats(int[][numscores],double[][numscores],double[], string[], int, int);

int main()
{
// Declaration and Initialization Statements
int bats[numplayers][numscores]; //Players number of at bats
double playerhits[numplayers][numscores]; //Players number of hits
string playernames[numplayers]; //Players names
double avgplayerscores[numplayers]; //Players average scores

// Function Calls
playerNames(playernames,numplayers);
batsHits(bats, playerhits, numplayers,numscores,playernames);
battingAverage(bats,playerhits,numplayers,numscores);
displayStats(bats,playerhits,avgplayerscores,playernames,numplayers,numscores);
}

//Collects the baseball players names from user
void playerNames(string playernames[], int numplayers)
{
int i;

for(i=0;i<numplayers;i++)
{
cout << "Please enter Player #" << i+1 << "'s name: ";
getline(cin,playernames[i]);
}
}

//Gets the number at bats and hits for each player
void batsHits(int bats [][numscores],double hits [][numscores], int numplayers, int numscore,string playernames[])
{
int i;
int j;

for(i=0;i<numplayers;i++)
{
for(j=0;j<numscores;j++)
{
cout << "Enter " << playernames[i] << "'s At Bats: " << endl;
cin >> bats[i][j];
cout << "Enter " << playernames[i] << "'s Hits: " << endl;
cin >> hits[i][j];
}
}
}

//Calculates the batting average for each player
void battingAverage(int bats[][numscores],double avgplayerscores[],int numplayers,int numscores)
{
int i = 0;
int j = 0;
double total = 0;

for(i;i<numscores;i++)
{
for(j=0;j<numplayers;j++)
{
total+=bats[j][i];
}
avgplayerscores[i]=(total/(j+1)*1.0);
total=0;
}
}

//Displays the players stats and calculates the total number of hits and bats for the whole team.
void displayStats(int bats[][numscores],double playerhits[][numscores],double avgplayerscores[],
string playernames[], int numplayers, int numscores)
{
int i = 0;
int j = 0;
double avgbats[10];
double avghits[10];
double total = 0;

for(i;i<numscores;i++)
{
for(j=0;j<numplayers;j++)
{
total+=bats[j][i];
}
avgbats[i]=(total/(j+1)*1.0);
total=0;
}

for(i;i<numscores;i++)
{
for(j=0;j<numplayers;j++)
{
total+=playerhits[j][i];
}
avghits[i]=(total/(j+1)*1.0);
total=0;
}

cout << endl << endl;
cout << "Player AB HITS AVE"
<< endl;
cout << playernames[0] << setw(17) << bats[0][0] << setw(17)
<< playerhits[0][0] << setw(17)
<< fixed << showpoint << setprecision(1) << avgplayerscores[0] << endl;

cout << playernames[1] << setw(17) << bats[1][0] << setw(17)
<< playerhits[1][0] << setw(17)
<< fixed << showpoint << setprecision(1) << avgplayerscores[1] << endl;

cout << playernames[2] << setw(17) << bats[2][0] << setw(17)
<< playerhits[2][0] << setw(17)
<< fixed << showpoint << setprecision(1) << avgplayerscores[2] << endl;

cout << playernames[3] << setw(17) << bats[3][0] << setw(17)
<< playerhits[3][0] << setw(17)
<< fixed << showpoint << setprecision(1) << avgplayerscores[3] << endl;

cout << playernames[4] << setw(17) << bats[4][0] << setw(17)
<< playerhits[4][0] << setw(17)
<< fixed << showpoint << setprecision(1) << avgplayerscores[4] << endl << endl;

cout << playernames[5] << setw(17) << bats[5][0] << setw(17)
<< playerhits[5][0] << setw(17)
<< fixed << showpoint << setprecision(1) << avgplayerscores[0] << endl;

cout << playernames[6] << setw(17) << bats[6][0] << setw(17)
<< playerhits[6][0] << setw(17)
<< fixed << showpoint << setprecision(1) << avgplayerscores[1] << endl;

cout << playernames[7] << setw(17) << bats[7][0] << setw(17)
<< playerhits[7][0] << setw(17)
<< fixed << showpoint << setprecision(1) << avgplayerscores[2] << endl;

cout << playernames[8] << setw(17) << bats[8][0] << setw(17)
<< playerhits[8][0] << setw(17)
<< fixed << showpoint << setprecision(1) << avgplayerscores[3] << endl;

cout << playernames[9] << setw(17) << bats[9][0] << setw(17)
<< playerhits[9][0] << setw(17)
<< fixed << showpoint << setprecision(1) << avgplayerscores[4] << endl << endl;

cout << "Totals" << setw(14) << fixed << showpoint << setprecision(1)
<< avgbats << setw(17) << avghits
<< setw(17) << endl << endl;
}

错误 LNK2019:引用了未解析的外部符号“void __cdecl battingAverage(int (* const)[3],double (* const)[3],int,int)” (?battingAverage@@YAXQAY02HQAY02NHH@Z)在函数 _main

它显然必须处理 main 函数中的函数 battingAverage 调用,我在这里搜索了这个错误,尝试将 c++ 编译器选项更改为“Console”,但没有帮助。请帮助大家,我确信这是一个小问题,但我已经厌倦了修复它。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com