title: Trouble calculating array average
body: <p>I am fairly new to c++ and I have a problem that has been stumping me for the longest time. I have to write a program that dynamically allocates two arrays large enough to hold a user-defined number of player names and player scores from a game I created.  Allow users to enter the scored in name-score pairs.  For each player that has played the game, the user types a string representing the name of the student, followed by an integer representing the player's score.  Once the names and the corresponding scored have been entered, the arrays should be passed into a function that sorts the data from the highest score to the lowest score (descending order).  Another function should be called that calculates the average score.  The program should display the player list from highest scoring player to lowest scoring player and the score averages with appropriate headings. Use pointer notation rather than array notation wherever possible</p>
  
  <p>here is my code: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  void sortPlayers(string[],int[], int);
  void calcAvg(int[], int);
  
  int main()
  {
      int *scores;
      string *names;
      int numPlayers,
      count;
  
      cout &lt;&lt; "How many players are there?: " &lt;&lt; endl;
      cin &gt;&gt; numPlayers;
  
      scores = new int[numPlayers];
      names = new string[numPlayers];
  
      for (count = 0; count &lt; numPlayers; count++)
      {
          cout &lt;&lt; "Enter the name and score of player " &lt;&lt; (count + 1)&lt;&lt; ":" &lt;&lt; endl;
          cin &gt;&gt; names[count] &gt;&gt; scores[count];
  
      }
  
  
      sortPlayers(names, scores, numPlayers);
  
      cout &lt;&lt; "Here is what you entered: " &lt;&lt; endl;
      for (count = 0; count &lt; numPlayers; count++)
      {
           cout &lt;&lt; names[count]&lt;&lt; " " &lt;&lt; scores[count] &lt;&lt; endl;
      }
      calcAvg(scores, numPlayers);
  
  
      delete [] scores, names;
      scores = 0;
      names = 0;
  
      return 0;
  
  
  }
  
  void sortPlayers(string names[], int scores[], int numPlayers)
  {
      int startScan, maxIndex, maxValue;
      string tempid;
  
      for (startScan = 0; startScan &lt; (numPlayers - 1); startScan++)
      {
          maxIndex = startScan;
          maxValue = scores[startScan];
          tempid = names[startScan];
          for(int index = startScan + 1; index &lt; numPlayers; index++)
          {
              if (scores[index] &gt; maxValue)
              {
                  maxValue = scores[index];
                  tempid = names[index];
                  maxIndex = index;
                  }
              }
              scores[maxIndex] = scores[startScan];
              names[maxIndex] = names[startScan];
              scores[startScan] = maxValue;
              names[startScan] = tempid;
          }
  }
  
  void calcAvg(int scores[], int numPlayers)
  { 
      int total = 0;
      double avg = 0;
  
      for(int i = 0; i &lt; numPlayers; i++)
  
          total += scores[numPlayers];
  
      avg = total/numPlayers; 
  
      cout &lt;&lt; "The average of all the scores is: " &lt;&lt; fixed &lt;&lt; avg &lt;&lt; endl;
  }
  </code></pre>
  
  <p>The sorting part works fine, but I am having trouble with the average displaying properly. It is being displayed as a negative number every time (ex -3157838390)
  Can anyone help me solve this problem? Does it have anything to do with my pointers? </p>