お久しぶりです(昨年のJavaクラス)。私の学校では提供されていないので、独学で C++ を学ぼうとしています。中級者向けの作業に入る前に、これまでに学んだこと (実際には構文のみ) をテストするためだけに、単純なプログラムを作成しました。とにかく、私は決して答えを探しているわけではないことを強調したいだけです。むしろ、物事を再考し、おそらく自分でそれを終わらせることができるように、私のロジスティクスについて質問してください. Javaでこれをうまく書くことができるので、C++ですべてうまくいくと思いましたが、変数の問題があります。デバッグしてステップスルーしようとしましたが、変数の一部が割り当てた値を取得していない理由がわかりませんでした。正しい方向に私を向けることができれば、本当に感謝しています。
// This program will create any number of teams the user chooses,
// give each a score and calculate the average of all the teams.
#include <iostream>
using namespace std;
int main(){
//number of teams
int teamCount;
//array to keep scores
int team[0];
//total of scores
int total=0;
//average of all scores
int average=0;
cout<<"How many teams do you want to keep scores of?"<<endl;
cin>>teamCount;
//cout<<teamCount;
//ask the person for the score as many time
//as there are teams.
for(int i=0; i<teamCount; i++){
cout<< "Give me the score of team "<< i+1<<":"<<endl;
cin>>team[i];
total+=team[i];
}
average = teamCount/total;
//output the list of the scores
for(int i=0; i<teamCount; i++){
cout<<"Team "<<i+1<<" score is:"<<team[0]<<endl;
}
cout<<"and the average of all scores is "<<average<<endl;
return (0);
}