Why my code is not running?

I don’t know why my code is not working
http://www.spoj.com/problems/TOANDFRO/

int main()
 {
 char a[100][100];
 int n,i,j,p,q;
 cin>>n;
 if(n==0)
 exit(0);
 for(i=0;i<40;i++)
   {
   for(j=0;j<n;j++)
    {
     cin.get(a[i][j]);
     if(a[i][j]=='\n')  //I am exiting when user enters the enter button
     goto jump;
    }
  }

  jump:

// cout<<i<<"\n"<<n<<"\n //I was testing whether the values of i & j are correct but value of j is not corrrect

   for(p=0;p<n;p++)
    {

   for(q=0;q<i;q++)
    {
    cout<<a[q][p];
    }

   }

   return 0;
  }

Your reading and writing is quite messy.

  1. I don’t see you taking in mind that you have several tests. This should look like that:

    while (1) { int n; std::cin >> n; if ( n == 0 ) break; // the other code }

  2. You have to improve you reading and writing. You are not reading right.