0
    #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 で参照

明らかに、メイン関数で呼び出している関数 battingAverage を処理する必要があります。ここでこのエラーを検索し、C++ コンパイラ オプションを「コンソール」に変更しようとしましたが、役に立ちませんでした。みんなを助けてください、それは小さな問題だと確信していますが、私はそれを修正しようとして疲れています.

4

1 に答える 1

4

あなたの宣言:

void battingAverage(int[][numscores],double[][numscores],int,int);

あなたの定義:

void battingAverage(int bats[][numscores],double [],int numplayers,int  numscores)

ご覧のとおり、2 番目の引数double[][numscores]vsに矛盾がありdouble[]ます。したがって、実際にはまったく異なる関数を定義しています。

于 2012-12-06T21:32:20.080 に答える