有人可以看看我的代码吗?循环时如何计算成绩,或者我可以从 StreamWriter 中取线并放入子字符串?我一直让它变得越来越混乱......我需要像这样展示它
学生得了多少分?得了B的学生得了多少?>得了C的学生有多少>得了d的学生... f...
using (StreamReader reader = new StreamReader("Student.txt"))
{
StreamWriter output = new StreamWriter("Result.txt");
String line;
line = reader.ReadLine();
while (line != null)
{
String name = line.Substring(0, 9);
String Asg1 = line.Substring(10, 3);
String Asg2 = line.Substring(16, 3);
String Test = line.Substring(22, 3);
String Quiz = line.Substring(28, 3);
String Exam = line.Substring(34, 3);
int intAsg1 = int.Parse(Asg1);
int intAsg2 = int.Parse(Asg2);
int intTest = int.Parse(Test);
int intQuiz = int.Parse(Quiz);
int intExam = int.Parse(Exam);
int percentAsg1 = (intAsg1 * 25) / 100;
int percentAsg2 = (intAsg2 * 25) / 100;
int percentTest = (intTest * 10) / 100;
int percentQuiz = (intQuiz * 10) / 100;
int percentExam = (intExam * 30) / 100;
// this part i dont get it~
**String Grade;
if (overallScore >= 70)
{
Grade = "A";
}
else if (overallScore >= 60)
{
Grade = "B";
}
else if (overallScore >= 50)
{
Grade = "C";
}
else if (overallScore >= 40)
{
Grade = "D";
}
else
{
Grade = "F";
}
}
}