我正在研究一个涉及数组的问题。我正在记录输入系统的学生的分数,每行两个分数,然后将它们存储到两个单独的数组中(测试一和测试二)。如果用户输入 e,系统将停止询问分数并打印出每个学生的分数值。
using System;
class Marks
{
static void Main()
{
string[] input;
string[] testOne = new string[40];
string[] testTwo = new string[40];
int count = 0;
Console.WriteLine("You are to enter two test marks per student.");
Console.WriteLine("Enter the letter e to end");
for (int i = 0; i <= 40; i++)
{
Console.Write("Enter marks for student " + (i+1) + ": ");
input = Console.ReadLine().Split(',');
if (input[0] == "e") break;
else if (input[0] != "e")
{
testOne[i] = input[0];
testTwo[i] = input[1];
}
count++;
}
Console.WriteLine("\nStudent Test 1 Test 2 Total");
Console.WriteLine("======= ====== ====== =====");
for (int i = 1; i <= count; i++)
{
Console.WriteLine(i + " " + testOne[i] + " " + testTwo[i]);
}
}
}
对于我输出数组值的最后一段代码,我似乎无法正确处理。我正在尝试为每个学生输出存储在数组中的值。
任何帮助,将不胜感激!
更新:
谢谢您的帮助!
示例输出如下,
You are to enter two test marks per student.
Enter the letter e to end.
Enter marks for student 1: 10, 14
Enter marks for student 2: 13, 9
Enter marks for student 3: 11, 7
Enter marks for student 4: 0, 18
Enter marks for student 5: e
Student Test 1 Test 2 Total
======= ====== ====== =====
1 10.0 14.0 26.0
2 13.0 9.0 24.0
3 11.0 7.0 20.0
4 0.0 18.0 27.0
如您所见,我可以为每个学生输入多个分数,最多 40 个学生或直到用户输入 e。不要担心总值,因为我可以自己解决,但现在我只想得到输出的值。