Start by breaking this into chunks: Write a couple of methods which do discrete bits of the code: Read the student answers, process them, display the results.
Start by writing the "read" method - you've got that, pretty much:
private string[] ReadStudent(string path)
{
return File.ReadAllLines(path);
}
Then write the "process" method:
private int[] ProcessStudent(string[] shouldBe, string[] was)
{
if (shouldBe.Length != was.Length)
{
throw new ArgumentException("Incorrect number of solutions!");
}
...
return new int[0];
}
(We'll look at filling that in in a moment)
And the "display" method:
private void DisplayResults(string[] shouldBe, int[] StudentErrors)
{
...
}
Your code to use them then becomes a lot more readable:
string[] correctAnswers = { "B", "D", "A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A" };
string[] studentAnswers = ReadStudent("Answers\\Answers.txt");
int[] studentErrors = ProcessStudent(correctAnswers, studentAnswers);
DisplayResults(correctAnswers, studentErrors);
Display results can calculate the numbers it needs to print from just the two parameters:
The number of correct answers is the length of the correctAnswers array, minus the length of the studentErrors array.
The number of incorrect answers is the length of the studentErrors array.
The question numbers that were wrong are in the studentErrors array.
I'll leave that as an exercise for the reader - it's pretty simple!
The "real work" is done in the ProcessStudent method - and it's pretty simple if you have been introduced to C# Collections such as the List<> class - but I'm going to assume you haven't, as arrays are a poor way to do this whole exercise if you are aware of Collections!
So we'll do this with arrays.
Start by declaring a temporary array to hold the wrong answer numbers - we'll make it big enough to hold a really bad student:
int[] wrong = new int[shouldBe.Length];
Now, we want to look at the answers given, and fill out the wrong answers. For that we need to indexes:
int[] wrong = new int[shouldBe.Length];
int wrongIndex = 0;
for (int i = 0; i < shouldBe.Length; i++)
{
}
Inside the loop it's pretty simple as well: check the answer, and if it's wrong, add the number to the errors array:
if (shouldBe[i] != was[i])
{
wrong[wrongIndex++] = i + 1;
}
The index is zero-based, so we need to add one to get a one-based question number.
Now all we need to do is return only the error question numbers in the "wrong" array:
int[] justTheWrongOnes = new int[wrongIndex];
for (int i = 0; i < wrongIndex; i++)
{
justTheWrongOnes[i] = wrong[i];
}
return justTheWrongOnes;
And we're done!
However, I'd suggest that you read and understand this rather than copy'n'paste it into your code and hand it in: if you hand that in exactly as I wrote it, your tutor will know that you didn't write it...so read it, understand it, and think of a similar solution that you can write yourself.