title: Code not running - C++ - exam training tests
body: <p>I have this very exercise which requires me to use a function named <strong>shift</strong>, which gets two parameters, one named <strong>n</strong>, number of items, and an array <strong>x</strong>, maximum 100 elements, therefor this function moves the array's items one by one. Then I need to inverse the array calling this function. I don't get why my code doesn't work. What should I do?</p>
  <pre><code>#include &lt;fstream&gt;
  using namespace std;
  
  void shift(int n, int x[]) {
      int aux1 = x[1], aux = x[n - 1];
      x[n - 1] = x[n];
      for (int i = n - 1; i &gt;= 2; i--) {
          int t = x[i - 1];
          x[i - 1] = aux;
          aux = t;
      }
      x[n] = aux1;
  }
  
  int main(){
      int n, x[100], v[100], rez[100]; cin &gt;&gt; n;
      for (int i = 1; i &lt;= n; i++) {
          cin &gt;&gt; x[i];
          v[i] = x[i];
      }
      int t = n, k = 1, j = 0, pos = 0;
      while (t !=  0) {
          k = 1, pos = 0;
          while (k != 0) {
              while (v[1] != x[t]&amp;&amp;pos==t) {
                  shift(n, v);
                  pos++;
              }
              k = 1;
          }
          j++;
          rez[j] = x[t];
          t--;
      }
      for (int i = 1; i &lt;= n; i++)
          cout &lt;&lt; rez[i] &lt;&lt; &quot; &quot;;
      return 0;
  }
  </code></pre>