我想知道我在该任务上做错了什么
我必须创建一个表格[] [,],从那里我从键盘上输入组的数量,每个组中的学生数量以及他们拥有多少科目。
对于每个学生,我必须为每个学科输入一个成绩。
我实际上不是我的错误在哪里。
因为我编写的程序无法正确显示完整的表(例如,如果在第1组中我有3个学生,而在第2组中我有1个学生,则每个第1组学生都会显示该表)
我还使用“浮点数”来计算每组所有年级的平均值,但是它显示了整数。
你能帮我吗?
我在下面附加了代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpecialTask
{
class Program
{
static int[][,] tab1;
static int iSub = 0;
static int iGro = 0;
static int iStu = 0;
static int note = 0;
static int iSum = 0;
static float fAvg = 0.0f;
static int Subjects(string sSubjects)
{
do
{
Console.WriteLine("Please enter a number of subjects (2-4):");
}
while ((!int.TryParse(Console.ReadLine(), out iSub)) || (iSub < 2) || (iSub > 4));
return iSub;
}
static int Groups(string sGroups)
{
do
{
Console.WriteLine("Please enter a number of groups (1-3):");
}
while ((!int.TryParse(Console.ReadLine(), out iGro)) || (iGro < 1) || (iGro > 3));
return iGro;
}
static int Students(string sStudents)
{
do
{
Console.WriteLine("Please enter a number of students(1-5): ");
}
while ((int.TryParse(Console.ReadLine(), out iStu) == false) || (iStu < 1) || (iStu > 5));
return iStu;
}
static int Notes(string sNotes)
{
do
{
Console.WriteLine("Please enter a note (2-5): ");
}
while ((!int.TryParse(Console.ReadLine(), out note)) || (note < 2) || (note > 5));
return note;
}
static void TabData()
{
int i, j, k;
Subjects("Please enter a number of subjects (2-4):");
Groups("Please enter a number of groups (1-3):");
tab1 = new int[iGro][,];
for (i = 0; i < iGro; i++)
{
Console.WriteLine("Group NO.{0}", 1 + i);
Students("Please enter a number of students(1-5): ");
tab1[i] = new int[iStu, iSub];
for (j = 0; j < iStu; j++)
{
for (k = 0; k < iSub; k++)
{
Console.WriteLine("Student NO.{0}", 1 + j);
Console.WriteLine("Subject NO.{0}", 1 + k);
tab1[i][j, k] = Notes("Please enter a note (2-5): ");
}
}
}
Console.WriteLine("\n");
Console.WriteLine("\n");
for (i = 0; i < iGro; i++)
{
Console.WriteLine("Group NO.{0}: ", 1 + i);
for (j = 0; j < tab1.Length; j++)
{
Console.WriteLine("Student NO.{0}/Group NO.{1}: ",1+ j, 1 + i);
for (k = 0; k < iSub; k++)
{
Console.Write("Subject NO.{0}: ", 1 + k);
Console.Write(tab1[i][j, k]);
Console.Write("\n");
}
Console.WriteLine("\n");
}
}
}
static void avgG()
{
int i, j, k;
TabData();
for (i = 0; i < iGro; i++)
{
for (j = 0; j < iStu; j++)
{
for (k = 0; k < iSub; k++)
{
iSum = iSum + tab1[i][j, k];
}
}
fAvg = iSum / iSub;
Console.WriteLine("Sum: " + iSum);
Console.WriteLine("Average of all grades for Group NO. {0}: {1}", i, fAvg);
}
}
static void Main(string[] args)
{
avgG();
Console.ReadKey();
Console.ReadKey();
}
}
}