Error Prompt

Okay, hello. I would like to ask if there is a problem with my codes that it gave me an error message that sounded like 'Fault: access violation at 0xXXXXX: read of address 0xXXXXXXX'.

I had no errors so far but when I tried running it this screen shows up.
I'm currently using Borland C++. Thanks in advance.

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
#include <iostream.h>
#include <conio.h>

int calcAverage(int[][3],double);
int findHighest(int[][3],int);

int main(){

	const int x = 3;
	int nombor[x][3] = {{1,2,3},{6,7,8},{11,12,13}};
   int average;

   average =  calcAverage(nombor,x);
   findHighest(nombor,x);

   cout << "The average of all the elements are : " << average << endl ;

	getch();

}

int calcAverage(int a[][3],double x){

	int sum = 0;
	int av;

   for(int i = 0; i < x ; a++){
   	for(int j = 0; j <=3 ; j++){
      	sum += a[i][j];
      }
   }

   av = sum / (x * 3);

   return av;

}

int findHighest(int a[][3],int x){

   int highest = a[0][0];

	for(int i = 0; i <= x ; a++){
   	highest = a[i][0];
   	for(int j = 0; j <=3 ; j++){
      	if (a[i][j] > highest){
         	highest = a[i][j];
         }
         cout << "Highest number in row " << i+1 << " is " << a[i][j] << endl ;
      }
   }

   return 0;

}
The condition on line 28 should be j < 3 .
The condition on line 43 should be i < x .
The condition on line 45 should be j < 3 .
lines 27-28:
lines 43-48:
Incrementing "a"?
Never changing "i"?

Also:
Why is "x" double in calcAverage?
You realise calcAverage returns an unlikely int?
Last edited on
Thanks, some careless manner over there. It worked.
you should check code again.
Topic archived. No new replies allowed.