This is part of a class assignment. I can't get in touch with my teacher, so I have nowhere else to turn.
There are two text files with this program, an answer key and a test "student" file for test, but it spits out the wrong results (For example, it says the second question was wrong, when in fact, it's correct.)
while (!correctFile.eof())
{
for (int i = 0; i <= MAX; i++)
{
answers[i] = correctFile.get();
}
}
I would do something like
1 2 3 4 5 6
for(int i = 0; correctFile && i <MAX; ++i)
{
int temp;
correctFile >> temp;
answer[i] = temp;
}
EOF means end of file there are other errors that should stop reading. Also If an array is the size of MAX then it starts at 0 and ends at MAX - 1 so you would read while it is less than MAX.
You have a slight prblem here grade = (20 - miss) / 20; this is what we call integer division. Say for example miss is 15 then 20 - 15 = 5. 5 / 20 = 0 (since integer if it was float it would be .25).
So change it to something like 20., 20f, 20.f, 20.0 or 20.0f
Oh and instead of calling the open method on your std::ifstream's you can use the constructor. something like: std::ifstream in("text.txt"); instead of
Sorry, int temp; should be char temp; forgot you were using a-d instead of 1-4. Though you are reading into answers twice instead of answers and student. so line 37 should be student[i] = temp;
With your sample files I get an output of
Now opening Correct Answers file...
Now opening Student Answers file...
For Question 4 you answered
D. The correct answer was C.
For Question 12 you answered
A. The correct answer was D.
For Question 17 you answered
C. The correct answer was D.
You missed 3 questions.
Your grade is 0.85
Process returned 0 (0x0) execution time : 0.261 s
Press any key to continue.