我的任务是计算保龄球平均数。我有五名球员,每个球员三场比赛。我目前正在运行两个循环,一个用于播放器,另一个用于游戏编号。我需要显示每个循环结束时球员的平均水平,以及球队在循环结束时的平均水平。
我修复了我的代码,并用下面的新代码替换了我的旧代码。在我在这里查看每个人的评论等之前,我一直在玩它,到那时我已经解决了。
但是谢谢大家!
#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
但是,对于仍然在那里的任何人,有没有办法让终端保持打开状态,而不必使用“sys(“PAUSE”);”?我真的很讨厌使用它。