"Program has stop working" problem.

So i was assigned a task(assingment) to write a program that calculates and display students Grade Point Average (GPA) and Cumulative Grade Point Average (CPA) for an Academic Advisor.

I also need to:
1. Use a file to record the Dean’s list. The program needs to write into file and read the file at the end to display the Dean’s list for their Academic Advisor.

2. Use another file to record the student details and any information related to
last semester results (example Cumulative total point and credits). Only
information of this semester will be entered through key board. After all the
processing is performed a new file will be created to prepare file next
semester processing. You need to design the file properly so that it make
your solution less complex and the name of the file should be related to the
semester name.

Now my program is not 100%, it consist of student's data input, calculating gpa and saving the data into file for displaying and for next semester use. I try to run it first to see if it got any error in it.

Unfortunately, before the the program end it display the popup message "Untitled1.exe has stop working".

Note : SIZE is the number of student.

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#define SIZE 1

using namespace std;

int main()
{
	int student, course[SIZE], course_credit[SIZE][16], course_mark[SIZE][16], counter1, counter2, counter3, counter4, counter5, i, j;
	
	char name[SIZE][30], id[SIZE][13], matric_number[SIZE][10], course_code[SIZE][17][9];
	
	float evaluation_point[SIZE][16], point[SIZE][16], total_point[SIZE], total_credit[SIZE], gpa[SIZE];
	
	string grade[SIZE][16];
	
	ofstream outdata;
	
	for ( student = 1; student <= SIZE; student++)
	{
		cout << "---------------------------------------------------------------------" << endl;
		cout << "\nEnter student " << student << " name :";
		cin.getline(name[student], 30);
		
		cout << "\nEnter student " << student << " id number :";
		cin.getline(id[student], 13);
		
		cout << "\nEnter student " << student << " matric number :";
		cin.getline(matric_number[student], 10);
		
		cout << "\nEnter number of course taken for student " << student << " :";
		cin >> course[student];
		cin.ignore();
		
		for ( counter1 = 1; counter1 <= course[student]; counter1++)
		{
			cout << "\nEnter course code for course " << counter1 << " :";
			cin.getline(course_code[student][counter1], 9);
			
			cout << "\nEnter course credit for course " << counter1 << " :";
			cin >> course_credit[student][counter1];
			cin.ignore();
			
			cout << "\nEnter course mark for course " << counter1 << " :";
			cin >> course_mark[student][counter1];
			cin.ignore();
		}
		
		for ( counter2 = 1; counter2 <= course[student]; counter2++)
		{
			if ( course_mark[student][counter2] >= 90 )
			{
				evaluation_point[student][counter2] = 4.00;
				grade[student][counter2] = "A+";
			}
			
			else if ( course_mark[student][counter2] >= 80 )
			{
				evaluation_point[student][counter2] = 4.00;
				grade[student][counter2] = "A";
			}
			
			else if ( course_mark[student][counter2] >= 75 )
			{
				evaluation_point[student][counter2] = 3.67;
				grade[student][counter2] = "A-";
			}
			
			else if ( course_mark[student][counter2] >= 70 )
			{
				evaluation_point[student][counter2] = 3.33;
				grade[student][counter2] = "B+";
			}
			
			else if ( course_mark[student][counter2] >= 65 )
			{
				evaluation_point[student][counter2] = 3.00;
				grade[student][counter2] = "B";
			}
			
			else if ( course_mark[student][counter2] >= 60 )
			{
				evaluation_point[student][counter2] = 2.67;
				grade[student][counter2] = "B-";
			}
			
			else if ( course_mark[student][counter2] >= 55 )
			{
				evaluation_point[student][counter2] = 2.33;
				grade[student][counter2] = "C+";
			}
			
			else if ( course_mark[student][counter2] >= 50 )
			{
				evaluation_point[student][counter2] = 2.00;
				grade[student][counter2] = "C";
			}
			
			else if ( course_mark[student][counter2] >= 45 )
			{
				evaluation_point[student][counter2] = 1.67;
				grade[student][counter2] = "C-";
			}
			
			else if ( course_mark[student][counter2] >= 40 )
			{
				evaluation_point[student][counter2] = 1.33;
				grade[student][counter2] = "D+";
			}
			
			else if ( course_mark[student][counter2] >= 35 )
			{
				evaluation_point[student][counter2] = 1.00;
				grade[student][counter2] = "D";
			}
			
			else if ( course_mark[student][counter2] >= 30 )
			{
				evaluation_point[student][counter2] = 0.67;
				grade[student][counter2] = "D-";
			}
			
			else
			{
				evaluation_point[student][counter2] = 0.00;
				grade[student][counter2] = "E";
			}
		}
		
		for ( counter3 = 1; counter3 <= course[student]; counter3++)
		{
			point[student][counter3] = course_credit[student][counter3] * evaluation_point[student][counter3];
		}
		
		for ( counter4 = 1; counter4 <= course[student]; counter4++)
		{
			total_point[student] += point[student][counter4];
			
			total_credit[student] += course_credit[student][counter4];
		}
		
		gpa[student] = total_point[student] / total_credit[student];
	}
	
	outdata.open("studentdata.txt");
	
	for ( i = 1; i <= SIZE; i++)
	{
		outdata << name[i] << endl << endl;
	
		outdata << id[i] << endl << endl;
		
		outdata << matric_number[i] << endl << endl;
		
		outdata << course[i] << endl << endl;
		
		for ( j = 1; j <= course[i]; j++)
		{
			outdata << course_code[i][j] << endl;
			outdata << course_credit[i][j] << endl;
			outdata << course_mark[i][j] << endl;
			outdata << evaluation_point[i][j] << endl;
			outdata << grade[i][j] << endl << endl;
		}
		outdata << endl << endl;
	}	
	
	outdata.close();
	
	return 0;
}


Any help is very appreciated. :)
When an array is SIZE long, the last element is array[SIZE-1]

array[SIZE] does not exist.

Your code in many, many places attempts to read too far and tries to read off the end of arrays.

For example, you create this array: course[SIZE] and then try to input like this cin >> course[student]; where student goes from 1 to SIZE, so at some point you are trying to input to course[SIZE], which does not exist.
Last edited on
Thank you, finally i know what the problem is.

So i change

for ( student = 1; student <= SIZE; student++)

in line 21 to

for ( student = 1; student <= SIZE - 1; student++)

and

for ( i = 1; i <= SIZE; i++)

in line 149 to

for ( i = 1; i <= SIZE - 1; i++)

and the problem is solved.

TQ again for the help.
Note that while that works, it is allocating something at i=0 but never uses it. Instead of going from 1 to SIZE (or 1 to SIZE-1 as you fixed it) you could have gone from 0 to SIZE-1. This gives you SIZE elements to work with instead of SIZE-1.
Topic archived. No new replies allowed.