I'm taking data from multiple text files using streamReader and putting it together into one text file using StreamWriter in c#, visual studio. Each text file has multiple lines, each line contains data entered by a user, so the number of lines changes over time. The streamwriter is correctly taking data from the streamreader and putting it into the text file, but only for one line, and then it stops working. Why is this?
It also calculates another variable but that seems to be unrelated, I'll include it anyway though just in case.
My Code:
using (StreamWriter sw = new StreamWriter("groups.txt"))
{
for (int l = 0; l < pupilDetailsID.Count; l )
{
for (int i = 0; i < skiTimeID.Count - 1; i )
{
for (int j = 0; j < quizID.Count; j )
{
if (skiTimeID[i] == quizID[j] && quizID[j] == pupilDetailsID[l])
{
string fullPupilRecord = pupilDetailsID[l] "~" pupilDetailsFirstName[l] "~" pupilDetailsSurname[l] "~" pupilDetailsClass[l]
"~" pupilDetailsNumber[l] "~" skiTime1[i] "~" skiTime2[i] "~" skiTime3[i] "~" skiTime4[i] "~" skiTime5[i] "~" skiTime[i] "~"
quizScore[j] "~" quizPercentage[j];
int quizScoreNumber = Convert.ToInt32(quizScore[j]);
decimal skiTimeDecimal = Convert.ToDecimal(skiTime[i]);
if (quizScoreNumber >= 7 && skiTimeDecimal <= 40)
{
groupLevel = "Advanced";
}
else if (quizScoreNumber >= 9 && skiTimeDecimal <= 50)
{
groupLevel = "Advanced";
}
else if (quizScoreNumber >= 5 && skiTimeDecimal <= 30)
{
groupLevel = "Advanced";
}
else if (quizScoreNumber >= 5 && skiTimeDecimal <= 50)
{
groupLevel = "Intermediate";
}
else if (quizScoreNumber >= 7 && skiTimeDecimal <= 60)
{
groupLevel = "Intermediate";
}
else if (quizScoreNumber >= 4 && skiTimeDecimal <= 40)
{
groupLevel = "Intermediate";
}
else
{
groupLevel = "Beginner";
}
fullPupilRecord = fullPupilRecord "~" groupLevel;
sw.WriteLine(fullPupilRecord);
fullPupilRecord = "";
}
}
}
}
sw.Close();
}
I don't really understand my own code, or c# in general (don't ask why I put myself in a position where i had to code, i know, i made a dumb decision but its too late now) so it would be appreciated if the answer was something i can copy and paste into my code to fix it, if possible
CodePudding user response:
So we through discussion, the solution is:
If you want to not exclude the last row, you should modify your judgment condition.
Modify for (int i = 0; i < skiTimeID.Count - 1; i )
to for (int i = 0; i < skiTimeID.Count; i )
.