有人可以看我的代碼嗎?我如何計算循環中的成績,或者我可以從StreamWriter中取出這一行並放入子字符串? 我一直讓它越來越雜亂......我需要像通過使用Streamwriter中的答案循環計數等級?
那樣顯示它那個得分A的學生有多少? 學生,進行了B獲得了多少?> 學生,進行了ç多少> 學生,進行了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";
}
}
}
爲了得到最好的答案,你可以從文件 –
可以發佈一個樣本行之前創建一個列表你試着讓你的問題更清楚一點? – Rohan
我得分後我想把它放在數組或什麼,這樣我就可以計算出「成績」有多少學生獲得 – user2844803