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