我有一个任务,用户必须输入一个名字,然后是一个分数,然后重复这个过程直到他们完成,按 Q,然后数组将显示名字和分数,然后给出所有这些的平均值分数。我现在拥有的就是这个。
static void inputPartInformation(string[] pl, double[] sc)
{
int i = 0;
do
{
Console.Write("Enter The Player's Name: ");
pl[i] = Console.ReadLine();
Console.Write("Enter Their Score: ");
sc[i] = double.Parse(Console.ReadLine());
}
while (pl[i++].CompareTo("Q") != 0);
}
static void displayParts(string[] pl, double[] sc)
{
int i = 0;
while (pl[i].CompareTo("Q") != 0)
{
Console.WriteLine("{0,15}{1,6}", pl[i], sc[i]);
++i;
}
}
static void Main(string[] args)
{
String[] players = new String[100];
double[] scores = new double[100];
inputPartInformation(players, scores);
displayParts(players, scores);
double average = scores.Average();
Console.WriteLine("The Average is: {0}", average);
Console.ReadLine();
}
当我尝试平均分数时,结果并不正确。