C# 成绩平均的学生名单

C# 成绩平均的学生名单,c#,arrays,C#,Arrays,在这里,当我分别计算学生的四个科目的平均值时,就像我继续计算学生的平均值一样,他的平均值与学生的平均值相加。为什么不计算每个学生的单独平均数?请帮忙 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { class stud { static void Main (

在这里,当我分别计算学生的四个科目的平均值时,就像我继续计算学生的平均值一样,他的平均值与学生的平均值相加。为什么不计算每个学生的单独平均数?请帮忙

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

 namespace ConsoleApplication3
 {
     class stud
     {
         static void Main (string[] args)
         {
             double[,] studentavg = new double[3, 4];
             double total = 0;
             int ch = 0;
             int i, j;

             while (ch == 0)
             {
                 for (i = 0; i < studentavg.GetLength(0); i++)
                 {
                     Console.WriteLine("Enter mark of student : {0}", i + 1);

                     for (j = 0; j < studentavg.GetLength(1); j++)
                     {
                         Console.WriteLine("Enter mark : {0}", j + 1);
                         studentavg[i, j] = Convert.ToDouble(Console.ReadLine());
                         total += studentavg[i, j];
                     }
                     Console.WriteLine("Average is: {0}", (total / studentavg.GetLength(1)));
                     Console.Write("Enter 1 for exit OR 0 for continue: ");
                     ch = Convert.ToInt16(Console.ReadLine());
                 }
             }
             Console.ReadLine();
         }
     }
 }
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
命名空间控制台应用程序3
{
类螺柱
{
静态void Main(字符串[]参数)
{
double[,]studentavg=新的double[3,4];
双倍合计=0;
int ch=0;
int i,j;
while(ch==0)
{
对于(i=0;i
学生之间永远不会将
总数
重置为0。尝试添加

total = 0
之后

ch = Convert.ToInt16(Console.ReadLine());
你排好了队 “双倍合计=0;” 在while循环之外。 您不需要每次都将其初始化为零吗

你也应该避免 “将.ToInt16转换为” 并用 如果(!int.TryParse(Console.ReadLine(),out ch)){error,请重新输入number}否则一切正常
尽量避免预定义的整数大小。从字符串到数字的转换总是会失败。

我相信几分钟后会有人指出问题所在。同时,只需使用调试器,逐行检查代码,并注意
total
变量的值。谢谢你,德克和克里斯没有问题@user3410213