title: Replacing each number within an array with the maximum number up to that point
body: <pre><code>#include&lt;iostream.h&gt;
  #include&lt;fstream.h&gt;
  ifstream f("date.in");
  using namespace std;
  int i;
  int P(int a[100],int k,int max)
  {
      max=a[1];
      for(i=2;i&lt;=k;i++)
              if(a[i]&gt;max)
                 max=a[i];
      return max;
  }
  int main()
  {
      int x,a[100],n;
      f&gt;&gt;n;
      for(i=1;i&lt;=n;i++)
          f&gt;&gt;a[i];
      for(i=2;i&lt;=n;i++)
          a[i]=P(a,i,x);
      for(i=1;i&lt;=n;i++)
          cout&lt;&lt;a[i]&lt;&lt;" ";
  }
  </code></pre>
  
  <p>My "date.in" file consists of the following :</p>
  
  <pre><code>12
  
  4 6 3 7 8 1 6 2 7 9 10 8
  </code></pre>
  
  <p>As the title states, the program should modify the array from within the file such that each number has the maximum value found in the array up to, and including, the position of that respective number. I've gone through it a hundred times but cannot figure out what's wrong with my code.</p>
  
  <p>When compiled, I get the following:</p>
  
  <pre><code>4 6 3 7 8 8 6 8 7 9 10 10
  </code></pre>
  
  <p>Any assistance would be appreciated.</p>