title: Need help adding winner to voting contest based on responses and frequency in c++
body: <p>I am having trouble with writing code to this prompt. Question: A school is conducting a poll of who should be the next apprentice. There are 5 candidates to choose from. The school has polled 20 students on campus. Write a program in C++ that tallies up the number of votes each candidate received and pronounces a winner. So in the code I wrote below, it does tally up the number of votes, but I do not know how to show the winner with printmax. Can someone help me print the winner? This is my code and idk why its not working:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  int main()
  {
      const int responseSize = 20; 
      int vote[responseSize];
      const int frequencySize = 6;
  
      for (int i = 0; i &lt; 21; i++){
          cout &lt;&lt;&quot;Please enter the next vote: &quot;&lt;&lt; endl;
          cin &gt;&gt; vote[i];
      }
  
      int frequency [ frequencySize ] = { 0 };
  
      for ( int answer = 0; answer &lt; responseSize;  answer++)
      ++frequency[vote[answer]];
  
      cout &lt;&lt; &quot;Rating&quot; &lt;&lt; setw(17) &lt;&lt; &quot;Frequency&quot; &lt;&lt;endl;
  
      for ( int rating = 1; rating &lt; frequencySize; rating++)
      cout &lt;&lt; setw(6) &lt;&lt; rating
      &lt;&lt; setw(17) &lt;&lt; frequency[rating] &lt;&lt; endl;
      
      return 0;
  
  }
  
  int printmax(int frequency[], int frequencysize)
  {
      int max =0, winner = 0, i=0;
      for (int i =0; i &lt; frequencysize; i++)
          if (frequency[i] &gt; max){
              max = frequency[i];
              winner = i;
          }
      cout &lt;&lt; &quot;and the winner is: &quot; &lt;&lt; i &lt;&lt; endl;
      return 0;
  }
  </code></pre>