title: How to fix 'No match for operator[]' error (c++)
body: <p>So I was given this array:
  <code>int arr[] = {60,70,30,15,17,80,16,75,90,85,40,75};</code></p>
  
  <p>I have to "fit" as much elements in this array as possible while having their sum being less than 500 (basically removing the biggest one until sum is less than 500).</p>
  
  <p>This is what i've tried:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;list&gt;
  
  using namespace std;
  
  int largestOfArray(int number[]);
  
  int main()
  {
      int sum = 0;
      int i = 0;
      int arr[] = {60,70,30,15,17,80,16,75,90,85,40,75};
      list&lt;int&gt; ar(arr,arr+12);
  
      for (i = 0; i &lt; 12;i++) 
          sum += arr[i];
  
      while (sum &gt; 500)
          ar.remove(largestOfArray(arr[12]));
  
      for (i = 0; i &lt; 12;i++)
          sum += arr[i];
  
      for (i = 0;i &lt; 12; i++)
          cout &lt;&lt; arr[i];
  
      cout &lt;&lt; sum;
      return 0;
  }
  
  int largestOfArray(int number[12]){
      int i = 0;
      int largest = number[0];
      for (i = 0;i &lt; 12;i++){
          if (largest &lt; number[i]) largest = number[i];
      }
      return largest;
  }
  </code></pre>
  
  <p>I keep getting this error:</p>
  
  <blockquote>
    <p>no match for 'operator[]' (operand types are 'std::__cxx11::list' and 'int')</p>
  </blockquote>
  
  <p>I know it has something to do with the <code>ar.remove(largestOfArray(ar[12]));</code> 
  but i dont know how to fix it.</p>