Hi there
Im trying to write up a code where two txt files are being compared to each other. One text files has the answer like "TFTTFFT" and the other txt files has the result including id like "1234 TT-FFT" The crazy part is that for each correct answer, the student gets 4 points and for every incorrect answer, the student gets -1 and for every no answer, which in this case is represented by a dash(-), the student gets zero. How do i go about writing up a code for this? ANy help will be very much appreciated. I dont necessarly need some one to code this for me as i have pretty much done the opening of files and stroing them in appropriate varaibles. Just a feed back on how to go about doing this would be nice. THank you in advance.

One file has a line like "TFTTFFT" which I presume are the correct answers (true/false) for seven questions. Does the second file contain multiple lines (one for each student) in the format "#### " followed by the same number of "T", "F" or "-" entries as there are in the original file? If so then I suggest

Reading the answer key (first line of first file) and converting it to an array of Char.

Reading each line of the answers (second) file, splitting that line into a student ID and answers, then converting the answers to an array of Char.

Comparing each element of the answers array with the corresponding element of the answer key array.

A select case will allow you to adjust the score for each scenario. A useful form of the select case is

Select Case True
    Case (boolean expression)
        'code
    Case (boolean expression)
        'code
    etc
End Select

Assuming you have read the files into some string variables, you could do something like this:

       Dim AnswerKey() As Char = "TTFFTT".ToCharArray
  Dim StudentAnswers() As Char = "T-FFFT".ToCharArray

  Dim NumCorrect As Int32 = StudentAnswers.Where(Function(ans As Char, index As Int32) ans = AnswerKey(index)).Count
  Dim NumSkipped As Int32 = StudentAnswers.Where(Function(ans As Char, index As Int32) ans = "-").Count
  Dim NumIncorrect As Int32 = StudentAnswers.Length - NumCorrect - NumSkipped

  Dim score As Int32 = (NumCorrect * 4%) - NumIncorrect

thank you all for the help..really appreciate you all taking your time out to help

This article has been dead for over six months. Start a new discussion instead.