私の割り当てはボウリング平均を計算することです。私は5人の選手と各選手に3人の選手がいます。私は現在、2つのループを実行しています.1つはプレイヤー用、もう1つはゲーム番号用です。私は、各ループの終わりにプレーヤーの平均を表示する必要があり、チームはそのループの最後に平均します。C++で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「)を使用する必要がない持っている方法はあり;」?私はそれを使用して本当に嫌いです。
を宣言し格納する必要がありますどのように多くの価値を知っているので、その下の行が実行されます。私はあなたがcinが実行しているように見えるようにするいくつかのデバッガアーチファクトを見ていると思うし、以下の行ではない。 –
みなさんありがとう!私はこれを投稿した直後にコードを操作していましたが、どういうわけか、いくつかの行を動かすことで動かすことができました。私はそれが偶然かもしれないと思う。次回、このようなコードを書くときには、私は間違いなくそれを取り締まるでしょう:P –
問題は単純にソースファイルを保存するのを忘れていた、または再構築時に自動的に再コンパイルされなかったことがあります。これらのことは非常にイライラする可能性があります。 –