title: Homework: Counting number of times an item occurs in a linked list
body: <p>Here's the assignment:
  Implement a method <code>countValue()</code> that counts the number of times an item occurs in a linked list. Remember to use the STL list.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>int countValue(list&lt;int&gt; front, const int item);
  </code></pre>
  
  <p>Generate 20 random numbers in the range of 0 to 4, and insert each number in the linked list. Output the list by using a method which you would call <code>writeLinkedList</code> which you would add to the ListP.cpp.</p>
  
  <p>In a loop, call the method <code>countValue()</code>, and display the number of occurrences of each value from 0 to 4 in the list.</p>
  
  <p>Remember that all the above is to be included in the file ListP.ccp
  Run: 2 3 4 0 1 0 2 4 2 3 3 4 3 3 3 0 0 2 0 2
  0 : 5, 1 : 1, 2 : 5, 3 : 6, 4 : 3 </p>
  
  <p>and here is what I have so far:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include&lt;iostream&gt;
  #include&lt;list&gt;
  #include&lt;tchar.h&gt;
  
  int countValue(list&lt;int&gt; front, const int item);
  
  using namespace std;
  int _tmain(int argc, _TCHAR* argv[])
  {
      list&lt;int&gt; front;
      int listCount;
      cout &lt;&lt; "Enter the size of the list: ";
      cin &gt;&gt; listCount;
      for (int i = 1; i &lt;= listCount; i++)
          front.insert(rand()%5);
      cout &lt;&lt; "Original List of Values: " &lt;&lt; endl;
      //writeLinkedList(front, " ");
      cout &lt;&lt; endl;
      for(int j=0;j&lt;5;++j)
          cout &lt;&lt; countValue (front,j) &lt;&lt; endl;
      cout &lt;&lt; endl;
      return 0;
  }
  
  int countValue(list&lt;int&gt; front, const int item)
  {   
      int count0;
      int count1;
      int count2;
      int count3;
      int count4;
      list&lt;int&gt; *List;
  
      for(list&lt;int&gt;::iterator i = front.begin(); i != front.end(); i++)
      {
          if(List-&gt;item == 0)
          {
              count0++;
          }
          if(List-&gt;item == 1)
          {
              count1++;
          }
          if(List-&gt;item == 2)
          {
              count2++;
          }
          if(List-&gt;item == 3)
          {
              count2++;
          }if(List-&gt;item == 4)
          {
              count4++;
          }
      }
  }
  </code></pre>
  
  <p>And here are the errors:</p>
  
  <pre><code>error C2065: 'list' : undeclared identifier line 5
  error C2062: type 'int' unexpected line 5
  error C2661: 'std::list&lt;_Ty&gt;::insert' : no overloaded function takes 1 arguments line 16
  error C3861: 'countValue': identifier not found line 21
  IntelliSense: no instance of overloaded function "std::list&lt;_Ty, _Ax&gt;::insert [with _Ty=int, _Ax=std::allocator&lt;int&gt;]" matches the argument list line 16
  IntelliSense: too few arguments in function call line 16
  error C2039: 'item': is not a member of 'std::list&lt;_Ty&gt;' lines 34, 38, 42, 46, 49
  IntelliSense: declaration is incompatible with "int countValue" (declared at line 5) line 25
  IntelliSense: class "std::list&lt;int, std:: allocator&lt;int&gt;&gt;" has no member "item" lines 34, 38, 42, 46, 49
  </code></pre>
  
  <p>I just want to know what I've done wrong and how to fix it and also if someone could help me figure out if I'm doing the countValue function wrong or not based on the instructions I would really appreciate it. I've read the chapter in our textbook several times, looked up tutorials on youtube and on Dream in Code, and still I can not figure this out. All helpful information is appreciated! </p>