title: Remembering a variable for next use
body: <p>I am having a problem with remembering a variable for next use and printing it out. I explain it more so understand what am I trying to do in my program.</p>
  
  <p>I have a person walking on a rectangle of size <code>a b</code>. I input starting location <code>x y</code> together with persons starting direction (North = y+1, South = y-1, East = x+1, West = x-1 // in my code it is S,J,V,Z). So my input looks like this:</p>
  
  <p><code>5 6</code> // a b
  <code>3 3 S</code> // x y s(this stands for starting direction - north)</p>
  
  <p>Now, I input number of moves <code>d</code> to generate for the person where it should move. 
  I enter number 4, and it can generate from 3 letters: D, L, P (Forward, turn left 90 degrees, turn right 90 degrees).</p>
  
  <p><code>4</code> // d
  <code>PLDL</code> // moves</p>
  
  <p>Now, the person should be walking by those moves. So if the person location and starting direction is <code>3 3 S</code>, it should just turn right (my direction is east but same location), then left (direction is north again, same location), then forward (now I move <code>y+1</code>, my direction is still north) and last move is turn left(direction west). So mi final location and direction (output) is:</p>
  
  <p><code>3 4 Z</code> </p>
  
  <p>Hope you understand it. If is something unclear, just ask in comment.</p>
  
  <p>I am getting weird output now, unreal numbers. I cant figure out how to put together variables and if conditions to solve it. My code takes first, starting direction and location, but later on when I generate moves, it should change to final output based on the generated string. Sadly, it doesnt work as I expect. Do you have any suggestions? My question is kind of wide but I hope we can solve it together.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  int n; // pocet uloh
  int a; // rozmer obdlznika a
  int b; // rozmer obdlznika b
  int i;
  
  
  static const char alpha[] = {'D', 'L', 'P'};
  char genRandom()
  {
  
      return alpha[rand() % strlen(alpha)];
  }
  // end of generator
  
  // funkcia na pohyb
  
  void pohyb (){
      int x[i];
      int y[i];
      string sD = ""; // starting direction
      string mD = ""; // middle direction (stored one for next use)
      string eD = ""; // ending direction to print out in output
      string d = ""; // number of generated directions eg. d=6 ==&gt; PDDLPPD
  
  
      for (int i=0; i &lt; d.size(); i++){
  
              if (sD[i] == 'S'){
                  if(d[i] == 'D'){
                      y[i] = (y[i]+1);
                  }else if(d[i] == 'L'){
                      mD[i] == 'Z'; 
                  }else if(d[i] == 'P'){
                      mD[i] == 'V'; 
                  }
              }else if (sD[i] == 'J'){
                  if(d[i] == 'D'){    
                      y[i] = (y[i]-1);
                  }else if(d[i] == 'L'){
                      mD[i] == 'V'; 
                  }else if(d[i] == 'P'){
                      mD[i] == 'Z'; 
                  }    
              }else if (sD[i] == 'V'){
                  if(d[i] == 'D'){
                      x[i] = (x[i]+1);
                  }else if(d[i] == 'L'){
                      mD[i] == 'S'; 
                  }else if(d[i] == 'P'){
                      mD[i] == 'J'; 
                  }    
              }else if (sD[i] == 'Z'){
                  if(d[i] == 'D'){
                      x[i] = (x[i]-1);
                  }else if(d[i] == 'L'){
                      mD[i] == 'J'; 
                  }else if(d[i] == 'P'){
                      mD[i] == 'S'; 
                  }    
              } // koniec if podmienky
      eD = mD[i];
      } // koniec for loopu
      // vystup
      for ( i = 0 ; i &lt; n ; i++ )
      {
  
          if(!((x[i]&gt;=0)&amp;&amp;(x[i]&lt;=a) &amp; (y[i]&gt;=0)&amp;&amp;(y[i]&lt;=b))){
              cout &lt;&lt; x[i] &lt;&lt; ' ' &lt;&lt; y[i] &lt;&lt; ' ' &lt;&lt; eD[i] &lt;&lt; ' ' &lt;&lt; "SPADOL" &lt;&lt; endl;
          }else{
              cout &lt;&lt; x[i] &lt;&lt; ' ' &lt;&lt; y[i] &lt;&lt; ' ' &lt;&lt; eD[i] &lt;&lt; endl;
          }
  
      } 
  
  } // koniec funkcie pohyb
  
  
  
  int main() {
  
      cin &gt;&gt; n;
      vector&lt;int&gt; x(n); // x position
      vector&lt;int&gt; y(n); // y position
      vector&lt;int&gt; d(n); // zombie directions generation ex. DPLDDP 
      vector&lt;string&gt; sD(n); // starting direction
      vector&lt;string&gt; eD(n); // ending direction
  
      while(!((n &gt;= 1)&amp;&amp;(n &lt;=15000)))
      {
          cout &lt;&lt; "max 15000" &lt;&lt; flush;
          cin &gt;&gt; n;
      }
  
  
      cin &gt;&gt; a &gt;&gt; b;
  
      while(!((a &gt;= 1)&amp;&amp;(a &lt;=100) &amp; (b &gt;= 1)&amp;&amp;(b &lt;= 100)&amp;&amp;(a!=b)))
      {
          cout &lt;&lt; "chyba max 100 alebo a!=b" &lt;&lt; endl;
          cin &gt;&gt; a &gt;&gt; b;
      }
  
  
      for (i = 0; i &lt; n; i++)
      {    
          cout &lt;&lt; "Uloha " &lt;&lt; i+1 &lt;&lt; ":" &lt;&lt; endl;
          cin &gt;&gt; x[i];
          cin &gt;&gt; y[i];
          cin &gt;&gt; sD[i];
  
          while(!((x[i]&gt;=0)&amp;&amp;(x[i]&lt;=a))) {
              cout &lt;&lt; "Try Again x: " &lt;&lt; flush;
              cin &gt;&gt; x[i];}
              while(!((y[i]&gt;=0)&amp;&amp;(y[i]&lt;=b))) {
                  cout &lt;&lt; "Try Again y: " &lt;&lt; flush;
                  cin &gt;&gt; y[i];}
  
                  cin &gt;&gt; d[i];
                  while(!((d[i]&gt;=1)&amp;&amp; (d[i]&lt;=200))) {
                      cout &lt;&lt; "Try Again d: " &lt;&lt; flush;
                      cin &gt;&gt; d[i];}
  
  
                      for (int counter=0; counter&lt;d[i]; counter++)
                      {
                          cout &lt;&lt; genRandom();
                      }
                      cout &lt;&lt; endl;
  
      }    // koniec for
  
      pohyb();
  system("pause");
  
  }
  </code></pre>
  
  <p>Sample input:</p>
  
  <pre><code>3
  3 5 
  2 2 S 
  8
  DPLDLPDD
  2 4 Z
  7
  PDDPDPD
  2 1 J
  8
  PPDLDDDD
  </code></pre>
  
  <p>and output</p>
  
  <pre><code>2 5 S SPADOL // spadol means his location is out of the rectangle
  3 4 J
  0 2 Z SPADOL
  </code></pre>