我似乎无法弄清楚如何显示值以及每个值与平均值的距离。这里是我的代码,但我知道这是不正确的。我一直在试图让所有东西都接近它想要的东西。显示7个整数以及每个平均值距离平均值
这是在线课堂的作业,所以没有太多的帮助选项。感谢您的任何意见!
int[] temp = new int[7];
int x;
string daysString;
for (x = 0; x < temp.Length; ++x)
{
Write("Enter the high temperature for the day: ");
daysString = ReadLine();
temp[x] = Convert.ToInt32(daysString);
}
WriteLine("\n-----------------------------------------");
WriteLine("The high temperature for each of the 7 days you entered: ");
for (x = 0; x < temp.Length; ++x)
Write("{0, 6}", temp[x]);
//Step 3. Compute Average
double average = temp.Average();
WriteLine("");
WriteLine("\n-----------------------------------------");
WriteLine("Average = {0}", average);
//Step 4. Find out how many numbers in the array are greater than the average.
int count = 0;
foreach (int i in temp)
{
if (i > average) count++;
}
Write("\n----------------------------------------------");
WriteLine("");
WriteLine("How many days away each high temperature is from the average");
WriteLine("{0, 6}", count);
您还没有提到的问题,_“我知道这是不正确” _是不够的。步骤4似乎不是问题, –
请阅读[MCVE]关于发布代码的指导。 “这是不正确的”对问题的解释很差。 –
我可以得到平均值,但代码的底部只显示一个数字不是7. – JenniferLopez