コーディングが新しく、配列のインデックス値を呼び出そうとしています。私は「プレーヤー2が最も重く、体重が72kgだ」と言いたいのですが、最大の体重アレイの指標値を得ることはできません。どんな助けでも大変ありがとうございます。申し訳ありませんが、私のコードは混乱していますが、私は鋭いことを学び始めました。配列内のインデックス値を呼び出す
{
double[] weight;
double[] height;
double totalHeight = 0;
double totalWeight = 0;
double averageHeight = 0;
double averageWeight = 0;
double maxWeightIndex =0;
double maxHeightIndex =0;
weight = new double [5] { 0, 0, 0, 0, 0};
double maxWeight = weight[0];
height = new double [5] { 0, 0, 0, 0, 0};
double maxHeight = weight[0];
for (int i = 0; i < weight.Length ; i++)
{
Console.WriteLine("What is the weight of player " + (i+1)); //asking user to what the weight of a player is
weight[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("What is the height of player " + (i+1)); //asking user to what the height of a player is
height[i]= Convert.ToInt32(Console.ReadLine());
totalHeight += height[i]; // total height
totalWeight += weight[i]; // total weight
averageHeight = (totalHeight/ weight.Length); //average height
averageWeight = (totalWeight/ weight.Length); //average weight
}
for (int i = 0; i < weight.Length ; i++)
{
if (maxWeight < weight[i]) maxWeight = weight[i]; //max value of weight
if (maxHeight < height[i]) maxHeight = height[i]; // max value of height
if (maxWeight < weight[i]) maxWeightIndex = i; //attempt at getting max weight index value
if (maxHeight < height[i]) maxHeightIndex = i; //attempt at getting max height index value
}
Console.WriteLine("The total weight of the team is " + totalWeight + "kg's");
Console.WriteLine("The total height of the team is " + totalHeight + "cm's");
Console.WriteLine("The average height of the team is " + averageHeight + "cm's");
Console.WriteLine("The average weight of the team is " + averageWeight + "kg's");
Console.WriteLine("Player " + maxWeightIndex + " is the heaviest player and he weighs " + maxWeight + "kg's");
Console.WriteLine("Player " + maxHeightIndex + " is the tallest player and he is " + maxHeight + "cm's");
}
あなたはあなただけにそれを変更した値よりもそれが少ない場合maxWeight'は最初にして*再び*テスト '変化しているが。明らかにこれは「偽」です。なぜ、同じ 'if'節の中で両方の変数を割り当てていないのですか(中括弧' {...} 'を使用します)? – UnholySheep
'averageHeight =(totalHeight/weight.Length);' 'weight'を参照してください.'height' – Amy
私が提案をすることができれば、' height'または 'weight'は1文字だけが異なるので、一方または両方の同義語を使用して、より明確に区別することができます。重量の代わりに「質量」が働くでしょうか?とにかく、ちょっと考えました。 – Amy