用C++计算两个不同的平均值

Mat*_*ler 2 c++ average dev-c++

我的任务是计算保龄球平均值.我有五名球员,每位球员有三场比赛.我目前有两个循环运行,一个用于播放器,另一个用于游戏号码.我需要在每个循环结束时显示玩家平均值,并且团队在该循环结束时平均.

我修复了我的代码,并用下面的新代码替换了我的旧代码.在我查看每个人的评论等之前,我正在玩它,然后我解决了它.

但是谢谢大家!

#include <iostream>

using namespace std;

int main()
{
//DECLARATIONS
const int PLAYER_NUMBER = 5; //There are five players total
const int GAME_NUMBER = 3; //There are three games total
const int MIN = 0; //Min number
const int MAX = 300; //Max number
double* playerScore; //The players' score of current game
double playerAverage = 0; //The current players' average
double teamAverage = 0; //The teams' average

//INPUT

for (int currentPlayer = 0; currentPlayer < PLAYER_NUMBER; currentPlayer++)
{//Set the current player number  

    for (int currentGame = 0; currentGame < GAME_NUMBER; currentGame++)
    {//Set the current game number
             //Get scores

             cout << "For Player " << (currentPlayer + 1) << ", enter score for game " << (currentGame + 1) << ": ";
             cin  >> playerScore[currentGame];


             if(playerScore[currentGame] < MIN || playerScore[currentGame] > MAX)
             {//Check range
                   cout << "The score must be between 0 and 300!\n";
                   currentGame--; //If there is an error, subtract the game number by one
             }//End If statement

             playerAverage += playerScore[currentGame];

             if(currentGame == 2)
             {//Current player average
                cout << endl << "The average for player " << (currentPlayer + 1) << " is: " << (playerAverage / 3) << endl << endl;
                teamAverage += playerAverage;
                playerAverage = 0;
             }//End If statement

    }//End game for-statement

}//End player for-statement

    cout << endl << "The average for the team is: " << (teamAverage / 15) << endl << endl;

//ENDING    
system("Pause");
return 0;    
}//Close main
Run Code Online (Sandbox Code Playgroud)

但是,对于那些仍然存在的人,有没有办法让终端保持打开状态,而不必使用"sys("PAUSE");"?我真的很讨厌使用它.

MRA*_*RAB 6

你在宣布double* playerScore,但我没有看到你在哪里分配存储.也许你在覆盖一些东西.