私の課題は、ボウリングの平均を計算することです。5 人のプレーヤーがいて、各プレーヤーに 3 つのゲームがあります。私は現在、プレイヤー用とゲーム番号用の 2 つのループを実行しています。これらの各ループの終了時にプレイヤーの平均を表示し、そのループの終了時にチームの平均を表示する必要があります。
コードを修正し、古いコードを以下の新しいコードに置き換えました。ここでみんなのコメントなどを見る前に遊んでいましたが、それまでに解決していました。
でもみんなありがとう!
#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");」を使用する必要がない方法はありますか? 私はそれを使うのが本当に嫌いです。