打印几次如何控制
如下代码最终打印,会吧“平均分是XX,高于平均分的有”也连续打几次,如何修改只把这句话打印1次?
string[] name = new string[4];
int[] score = new int[4];
int sum = 0, avg;
for (int i = 0;i<name.Length;i++)
{
//Console.WriteLine("第{0}位同学的姓名:{0},他的分数:{1}",name[i], int.Parse(score[i]));
//name[i]= Console.ReadLine();
//score[i] = int.Parse(Console.ReadLine());
Console.Write("第{0}位同学的姓名:{1}",i+1,name[i]);
name[i]=Console.ReadLine();
Console.Write("第{0}位同学的分数:{1}",i+1,score[i]);
score[i] = int.Parse(Console.ReadLine());
//求取总分数值
sum += score[i];
}
//求avg,找出高于avg的所有人姓名及其分数
avg = sum / score.Length;
for (int i = 0; i < score.Length; i++)
{
if (score[i] > avg)
{
//Console.WriteLine("平均分是:{0},高于平均分的同学有:{1}",avg, name[i]);
Console.WriteLine("平均分是:" + avg + "高于平均分的同学有:" + name[i]);
}
}