compare two input files

For the most part my code is working the only error which i think is that i coded the file names instead of letting the user enter the names.

the program will read one file with answers and the other with students answers and compare them and print the results.
https://www.chegg.com/homework-help/questions-and-answers/lab-lesson-10-consists-two-parts-also-10-bonus-points-earn-bonus-points-complete-participa-q25395189

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	// Arrays
	char answers[20];
	char student[15][20];
	double percentages[15];

	// Create file objects.
	ifstream correctInputFile;
	ifstream studentInputFile;


	// Open files.
	correctInputFile.open("answers.txt");
	studentInputFile.open("student.txt");

	if (correctInputFile && studentInputFile) // If the files opened correctly, continue.
	{

		// Insert contents of answers.txt into an array.
		int count = 0; // Counter for lop
		while (count < 20 && correctInputFile >> answers[count])
			count++;

		// Insert contents of student.txt into a two-dimensional array.
		int rows = 0;
		while (rows < 15 && studentInputFile >> student[rows][0])
		{
			for (int columns = 1; columns < 20; columns++)
				studentInputFile >> student[rows][columns];
			rows++;
		}

		// Close the files.
		correctInputFile.close();
		studentInputFile.close();

		// Compare the two arrays
		int numberOfCorrectAnswers;
		int numberOfIncorrectAnswers;
		for (int secondIndex = 0; secondIndex <= rows; secondIndex++)
		{
			if (secondIndex != 0)
			{
				double percentCorrect = (numberOfCorrectAnswers / 20.0) * 100;
				percentages[secondIndex - 1] = percentCorrect;
				cout << numberOfIncorrectAnswers << " questions were missed";
				if (percentCorrect == 100) {
					cout << "0 questions were missed" << endl;
					cout << "The student passed";
				}
				else if (percentCorrect >= 70)
				{
					cout << "The student passed";
				}
				else
				{
					cout << "The student failed";
				}
				cout << endl;
			}

			
			if (secondIndex != rows)
			{
				numberOfCorrectAnswers = 0; // Initialize accumulator to zero
				numberOfIncorrectAnswers = 0; // Initialize accumulator to zero
				cout << "";

				for (int index = 0; index < 20; index++)
				{
					if (answers[index] == student[secondIndex][index])
						numberOfCorrectAnswers++;
					else
					{
						numberOfIncorrectAnswers++;
						cout << "Question " << (index + 1) << " has incorrect answer '" << student[secondIndex][index] << "', the correct answer is '" << answers[index] << "'" << endl;
					}
				} // end if
				
			} // end nested for loop

		} // end for loop


	}
	else
		cout << "File \"invalidfile.txt\" could not be opened" << endl;
	system("pause");
	return 0;
} // end function main() 
Registered users can post here. Sign in or register to post.