Program doesnt' work

I don't know why the program stops after line 27, it doesn't read ch or anything else after the first array

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
  #include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream IN("input.txt");
ofstream OUT("output");
int X[2][4][5];
if ( IN && OUT)
{
 int n_el, idx_el=1;
 IN>>n_el;
 for( int i=0; i<2; i++)
 {
    for(int j=0; j<4; j++)
        {
            for(int z=0; z<5; z++)
            {
               while(idx_el<n_el)
               {
                IN>> X[i][j][z];
                cout<<X[i][j][z]<<endl;
                idx_el++;
               }
            }
        }
 }
                char ch;
                int x;
                IN>> ch;
                cout<<ch;
                    if(ch=='H')
                    { IN>>x;
                            for(int i=0;i<2;i++)
                            {
                                for(int z=0;z<5;z++)
                                {
                                    while(idx_el<n_el)
                                    {
                                    OUT<<X[i][x][z]<<" ";
                                    idx_el++;
                                    }
                                }
                            OUT<<"  "<<endl;
                            }

                    }
                        if(ch=='V')
                        {int y;
                         IN>>y;

                                    for(int i=0;i<2;i++)
                                    {
                                        for(int j=0;j<4;j++)
                                        {
                                        OUT<<X[i][j][y]<<" ";
                                        }
                                        OUT<<"  "<<endl;
                                    }


                        }


}

else

    cout<<"errore con i files";
IN.close(); OUT.close();


}

because what I am trying to do is:
In the file input i can write this for example:
30
1 2 1 0 0 0 2 2 3 1
0 0 1 1 1 1 1 2 1 0
1 1 0 1 0 0 2 2 2 0
1 2 2 2 2 2 1 1 2 1

H 1

So my array will be filled with the first 30 values.
After that it should read the char H and proceed. But it doesn't and I don't know why.
Topic archived. No new replies allowed.