הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Tuesday, August 6, 2013 6:28 AM
In vb.net I'm trying to write a program that will compare two arrays. The comparison is between test answers (multiple choice) and the correct answer key and in turn display whether each question was answered correctly or incorrectly.
Thanks for your help.
All replies (5)
Tuesday, August 6, 2013 7:35 PM ✅Answered
Sub Main()
'First of all load your correct answers to the Question array and load the
'student's answers to the answers array. The result array keeps the result for each question.
Dim Questions(0 To 5) As Int16
Dim Answers(0 To 5) As Int16
Dim Resault(0 To 5) As Boolean
Questions(0) = 0
Questions(1) = 1
Questions(2) = 2
Questions(3) = 3
Questions(4) = 4
Questions(5) = 5
For a1 As Int16 = 0 To Answers.Count - 1
'Collect the answers from the student for comparison.
Console.Write("Enter the choice for question " & a1 & " :")
Answers(a1) = Console.ReadLine
Next
For i As Int16 = 0 To Questions.Count - 1
'Compare the answers with the questions and save the resault in Resault.
Resault(i) = (Questions(i) = Answers(i))
Console.WriteLine(IIf(Resault(i), "The answer is correct", "The answer is incorrect."))
Next
End Sub
Tuesday, August 6, 2013 7:54 PM ✅Answered
There are tons of ways to do this, but I will imagine this is for homework so they want you to do it a specific way. This version of your code will compile and works (for example if you answer 0 to question 0 it considers that correct, but if you answer 2 to question 3 it will consider that wrong).
Sub Main()
'First of all load your correct answers to the Question array and load the
'student's answers to the answers array. The result array keeps the result for each question.
Dim Questions(0 To 5) As Integer
Dim Answers(0 To 5) As Integer
Dim Resault(0 To 5) As Boolean
Questions(0) = 0
Questions(1) = 1
Questions(2) = 2
Questions(3) = 3
Questions(4) = 4
Questions(5) = 5
For a1 As Integer = 0 To Answers.Count - 1
'Collect the answers from the student for comparison.
Console.Write("Enter the choice for question " & a1 & " :")
Answers(a1) = CInt(Console.ReadLine)
Next
For i As Integer = 0 To Questions.Count - 1
'Compare the answers with the questions and save the resault in Resault.
Resault(i) = (Questions(i) = Answers(i))
Console.WriteLine(IIf(Resault(i), "The answer is correct", "The answer is incorrect."))
Next
Console.ReadLine()
End Sub
But if you have any specific question about this code assignment, then please explain in detail.
Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
Tuesday, August 6, 2013 8:22 PM ✅Answered
If Matt is right - that this is homework - then this won't do you any good, but if it's not, then you might want to have a look at a whole different approach for this.
It's about halfway down in this thread from a while back:
I hope that gives you some ideas. :)
Please call me Frank :)
Tuesday, August 6, 2013 6:49 AM | 1 vote
You haven't indicated what the problem is. Is the comparison not working correctly, or is there an error message? If it's not working then you should show the data in the arrays and code you are using and describe what you expected to happen and what actually happened. If there is an error message then you should show the section of code where the error occurs, the exact error message, and the values of the relevant variables.
Tuesday, August 6, 2013 9:19 PM
http://www.google.com/#bav=on.2,or.r_qf.&fp=bb5efefb0fc1c0dc&q=compare+two+arrays+vb.net
Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.