Help with the code!!

Why is the code taking more than 9 inputs?
(1 Input= 4 integers separated by spaces on a single line)
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
#include<iostream>
#include<algorithm>
#include<conio.h>
#include<cstdio>
#define NORTH 3
#define EAST 2
#define WEST 1
#define SOUTH 0
int main()
{
int mat[3][3],i,j,n,e,w,s;
for(i=0;i<3;i++)
  std::fill_n(*(mat+i),3,0);
  for(j=0;j<=2;j++)
  {
   for(i=2;i>=0;i--)
   {
    scanf("%d%d%d%d",&n,&e,&w,&s);
    if(n==1)
    {        
     mat[i][j]|=(1<<NORTH);
     if(i!=2)
     mat[i-1][j]|=(1<<SOUTH);
    }
    if(e==1)
    {
     mat[i][j]|=(1<<EAST);
     if(j!=2)
     mat[i][j+1]|=(1<<WEST);
    }
    if(w==1)
    {
     mat[i][j]|=(1<<WEST);
     if(j!=0)
     mat[i][j-1]|=(1<<EAST);
    }
    if(s==1)
    {
     mat[i][j]|=(1<<SOUTH);
     if(i!=0)
     mat[i+1][j]|=(1<<NORTH);
    }
    }
  }
    for(i=0;i<3;i++)
    {
   for(j=0;j<3;j++)
   std::cout<<mat[i][j]<<' ';
   std::cout<<'\n';
   }
   getch();
    return 0;
    }
Probably because you are accessing the matrix out of bounds, affecting the values of the indexes.
1
2
if(i!=2)
   mat[i-1][j]|=(1<<SOUTH);
Suppose that i==0

By the way, you need to learn to indent.
Topic archived. No new replies allowed.