Errors I'm unable to recognize

The program reads IDs and scores for a test and then outputs the ID, score, points based on score, and the grade. I'm getting all kinds of different errors, such as memory errors, DLL errors, and it says I'm using a certain char variable without it being initialized.

The first line in the file looks like: FFTFFTFFTTFTTFFTTFTF
Each line afterwards looks like: ABC56236 FFTFTFTTFTFTTFTTTFTF

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
96
97
98
99
100
101
#include <iostream>
#include <fstream>

using namespace std;

void process(char ID[], char score[], char answers[]);
int calcGrade(int pts);


int main()
{
	char score[21];
	char ID[9];
	char trueAnswers[21];
	char discard = ' ';

	ifstream studentScores;
	studentScores.open("ex6_studentScores.txt"); // this is only part of the entire file name, which is excluded here.

	studentScores.get(trueAnswers, 20); // read the correct answers
	studentScores.get(discard);         // read the newline character      

	while (studentScores)  // read and store info into ID and score and  process and output the data.
	{
		studentScores.get(ID, 8);         // read the student ID
		studentScores.get(discard);       // read the newline character after the student ID
		studentScores.getline(score, 20); // read the student's scores

		process(ID, score, trueAnswers);  
	}

	studentScores.close();
	system("pause");
	return 0;
}

void process(char ID[], char score[], char answers[]) // calculate points based on correct and incorrect answers; output results
{
	int points = 0;

	for (int i = 0; i < 20; i++)
	{
		if (score[i] = ' ')
		{
			points += 0;
		}

		else if (answers[i] == score[i])
		{
			points += 2;
		}

		else
		{
			points--;
		}
	}

	if (points < 0)
	{
		points = 0;
	}

	cout << ID << " " << score << " " << points << " " << calcGrade(points);
	cout << endl;

}



int calcGrade(int pts)
{
	char grade; // this is the variable it says I can't use w/o initializing

	switch (pts / 4)
	{
	case 1:
	case 2:
	case 3:
	case 4:
	case 5:
		grade = 'F';
		break;
	case 6:
		grade = 'D';
		break;
	case 7:
		grade = 'C';
		break;
	case 8:
		grade = 'B';
		break;
	case 9:
	case 10:
	        grade = 'A';
		break;
	}


	return grade;
}
Last edited on
> I'm getting all kinds of different errors
¿why bother to actually write the error messages?


> I'm using a certain char variable without it being initialized.
a certain char... ¿no name? ¿no line number?
Topic archived. No new replies allowed.