這個里面哪里錯了,if (score[i] > avg)提示超出數組限界?
? ? ? ? ? ? string[] name = new string[8];
? ? ? ? ? ? int[] score = new int[8];
? ? ? ? ? ? for (int i = 0; i < name.Length; i++)?
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.Write("輸入姓名:");
? ? ? ? ? ? ? ? name[i] = Console.ReadLine();
? ? ? ? ? ? ? ? Console.Write("輸入分數:");
? ? ? ? ? ? ? ? score[i] = int.Parse(Console.ReadLine());
? ? ? ? ? ? }
? ? ? ? ? ? int sum = 0, avg;
? ? ? ? ? ? for (int i = 0; i < score.Length; i++)?
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum += score[i];
? ? ? ? ? ? }
? ? ? ? ? ? avg = sum / score.Length;
? ? ? ? ? ? Console.WriteLine("平均分是"+avg+",高于平均分的有");
? ? ? ? ? ? for (int i = 0; 0 < score.Length; i++)
? ? ? ? ? ? ? ? if (score[i] > avg)
? ? ? ? ? ? ? ? ? ? Console.Write(name[i]+" ");
2016-08-15
? ? ? ? ? ? for (int i = 0; 0 < score.Length; i++)?
? ? ? ? ? ? ? ? ?//這一行中,請把中間的循環條件改為i<score.Length,不然程序會一直在這里循環。
2016-08-15
for (int i = 0; 0 < score.Length; i++)
同學你好好看看這句代碼
2016-08-15
你可以參考一下我的代碼?
2016-08-15
? ? ? ? ? ? string[] name = { "景珍", "林惠洋", "成蓉", "洪南昌","龍玉民","單江開","田武山","王三明" };
? ? ? ? ? ? int[] score = { 90,65,88,70,46,81,100,68};
? ? ? ? ? ? int sum = 0;
? ? ? ? ? ? double avg;
? ? ? ? ? ? //計算總分
? ? ? ? ? ? for (int i = 0; i < score.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum += score[i];
? ? ? ? ? ? }
? ? ? ? ? ? //計算平均分
? ? ? ? ? ? avg = sum / score.Length;
? ? ? ? ? ? Console.Write("平均分是"+avg+",");
? ? ? ? ? ? //統計高于平均分的人數并逐一輸出
? ? ? ? ? ? Console.WriteLine("高于平均分的有:");
? ? ? ? ? ? int j;
? ? ? ? ? ? for ( j= 0; j< name.Length; j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (score[j] > avg)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.Write(name[j]+" ");
? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? }