title: C++ : User Input of Names and Scores, unknown number of names, compare scores
body: <p>I need some help with homework. I need to create a program that gets names from the user, then asks for 5 scores for those names. There is an unknown number of names being entered. After the user finishes entering each name and scores, the program needs to calculate the average score after dropping the high and low scores. For example, the user enters "Nick" w/scores 8,7,6,5,4. Scores 8 and 4 would be dropped, and the average would be calculated off of 5,6,7. 
  My questions are:
  How do I connect the input names with their corresponding scores?
  How do I fix this error "Stack around the variable 'scoreArray' was corrupted?"
  Below is the code I have so far.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  double calcAvgScore(int, int, int, int, int);
  int checkValid(int);
  int findLowest(int, int, int, int, int);
  int findHighest(int, int, int, int, int);
  
  int main() {
  
      string contestant;
      int score, i, arrayPos = 0;
      int scoreArray[5] = {};
      double avgScore;
  
      cout &lt;&lt; "Enter the name of the star. Enter Done if no more stars.\n";
      cin &gt;&gt; contestant;
      while (contestant != "Done" &amp;&amp; contestant != "done")
      {
          for  (i = 1; i &lt; 6; i++)
          {
              cout &lt;&lt; "Enter judge " &lt;&lt; i &lt;&lt; " score: ";
              cin &gt;&gt; score;
              checkValid(score);
              scoreArray[arrayPos] = score;
              ++arrayPos;
          }
  
          avgScore = calcAvgScore(scoreArray[0], scoreArray[1], scoreArray[2],
                                  scoreArray[3], scoreArray[4]);
          cout &lt;&lt; "Average Score " &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; avgScore &lt;&lt; endl;
          cout &lt;&lt; endl;
          cout &lt;&lt; "Enter the name of the star. Enter Done if no more stars.\n";
          cin &gt;&gt; contestant;
      }
  
  
      system("pause");
      return 0;
  }
  
  double calcAvgScore(int score1, int score2, int score3, int score4,
                      int score5) {
      int low, high, totalScore;
      low = findLowest(score1, score2, score3, score4, score5);
      high = findHighest(score1, score2, score3, score4, score5);
      totalScore = score1 + score2 + score3 + score4 + score5 - low - high;
      double avgScore = double(totalScore) / 3;
      return avgScore;
  }
  
  int checkValid(int score) {
      while (score &lt; 1 || score &gt; 10)
      {
          cout &lt;&lt; "Please enter a valid score: ";
          cin &gt;&gt; score;
      }
      return score;
  }
  
  int findLowest(int score1, int score2, int score3, int score4, int score5) {
      int low = 11;
      int array[5] = { score1, score2, score3, score4, score5 };
      for (int i = 0; i &lt; 5; i++)
      {
          if (array[i] &lt; low)
          {
              low = array[i];
          }
      }
      return low;
  }
  
  int findHighest(int score1, int score2, int score3, int score4, int score5) {
      int high = 0;
      int array[5] = { score1, score2, score3, score4, score5 };
      for (int i = 0; i &lt; 5; i++)
      {
          if (array[i] &gt; high)
          {
              high = array[i];
          }
      }
      return high;
  }
  </code></pre>
  
  <p>corrected code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  double calcAvgScore(int, int, int, int, int);
  int checkValid(int);
  int findLowest(int, int, int, int, int);
  int findHighest(int, int, int, int, int);
  
  int main() {
  
      string contestant;
      int score, i, y, arrayPos;
      int scoreArray[5] = {};
      vector&lt;string&gt; names{};
      double avgScore, maxAvg;
      vector&lt;double&gt; avgScoreVec{};
  
      cout &lt;&lt; "Enter the name of the star. Enter Done if no more stars.\n";
      cin &gt;&gt; contestant;
      while (contestant != "Done" &amp;&amp; contestant != "done")
      {
          names.push_back(contestant);
          arrayPos = 0;
          for  (i = 1; i &lt; 6; i++)
          {
              cout &lt;&lt; "Enter judge " &lt;&lt; i &lt;&lt; " score: ";
              cin &gt;&gt; score;
              score = checkValid(score);
              scoreArray[arrayPos] = score;
              ++arrayPos;
          }
          avgScore = calcAvgScore(scoreArray[0], scoreArray[1], scoreArray[2],
          scoreArray[3], scoreArray[4]);
          avgScoreVec.push_back(avgScore);
          cout &lt;&lt; endl;
          cout &lt;&lt; "Enter the name of the star. Enter Done if no more stars.\n";
          cin &gt;&gt; contestant;
      }
  
      maxAvg = *max_element(avgScoreVec.begin(), avgScoreVec.end());
      y = find(avgScoreVec.begin(), avgScoreVec.end(), maxAvg) - avgScoreVec.begin();
      cout &lt;&lt; "... and the winner is " &lt;&lt; names[y] &lt;&lt; " with a score of " &lt;&lt; 
      setprecision(2) &lt;&lt; fixed &lt;&lt; maxAvg &lt;&lt; endl;
  
      system("pause");
      return 0;
  }
  
  double calcAvgScore(int score1, int score2, int score3, int score4, 
                  int score5) {
      int low, high, totalScore;
      low = findLowest(score1, score2, score3, score4, score5);
      high = findHighest(score1, score2, score3, score4, score5);
      totalScore = score1 + score2 + score3 + score4 + score5 - low - high;
      double avgScore = double(totalScore) / 3;
      return avgScore;
  }
  
  int checkValid(int score) {
      while (score &lt; 1 || score &gt; 10)
      {
          cout &lt;&lt; "Please enter a valid score: ";
          cin &gt;&gt; score;
      }
      return score;
  }
  
  int findLowest(int score1, int score2, int score3, int score4, int score5) {
      int low = 11;
      int array[5] = { score1, score2, score3, score4, score5 };
      for (int i = 0; i &lt; 5; i++)
      {
          if (array[i] &lt; low) 
          {
              low = array[i];
          }
      }
      return low;
  }
  
  int findHighest(int score1, int score2, int score3, int score4, int score5) {
      int high = 0;
      int array[5] = { score1, score2, score3, score4, score5 };
      for (int i = 0; i &lt; 5; i++)
      {
          if (array[i] &gt; high)
          {
              high = array[i];
          }
      }
      return high;
  }
  </code></pre>