title: Input Validation: My Program cannot accept negative numbers but it is accepting them and I'm really confused on what to do
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  // Function Prototype
  
  void sortArray(int array[], int size);
  void showArray(const int arr[], int size);
  void average(int testScores[], int size);
  
  int main()
  {
      int *testScores;
      int numGrades,count;               
  
      cout &lt;&lt; "How many grades? " &lt;&lt; endl;
      cin &gt;&gt; numGrades;
  
      testScores = new int[numGrades];
      cout &lt;&lt; "Please enter the scores below." &lt;&lt; endl;
  
      for (count = 0; count &lt; numGrades; count++)
      {
          cin &gt;&gt; testScores[count];
      }
  
      sortArray(testScores, numGrades);
      showArray(testScores, numGrades);
      average(testScores, numGrades);
      delete[] testScores;
      testScores = 0;
      system("pause");
      return (0);
  }
  
  //function for ascending order
  
  int * testScores[];
  
  void sortArray(int array[], int size)
  {
      bool swap;
      int temp;
  
      do
      {
         swap = false;
          for (int count = 0; count &lt; (size - 1); count++)
          {
              if (array[count]&gt; array[count + 1])
              {
                  temp = array[count];
                  array[count] = array[count + 1];
                  array[count + 1] = temp;
                  swap = true;
              }
          }
      } while (swap);
  }
  
  // display array function
  
  void showArray(const int arr[], int size)
  {
      cout &lt;&lt; "                        Scores in ascending order." &lt;&lt; endl;
      for (int count = 0; count &lt; size; count++)
      {
  
          cout &lt;&lt; "  " &lt;&lt; arr[count] &lt;&lt; "";
  
      }
      cout &lt;&lt; endl;
      cout &lt;&lt; endl;
  }
  
  // function to get average of the array
  
  void average(int testScores[], int numGrades)
  {
      float total = 0.0;
  
      for (int count = 0; count &lt; numGrades; count++)
      {
  
          total += testScores[count];
      }
  
      float average = total / numGrades;
      cout &lt;&lt; "                This is the average of the scores entered." &lt;&lt; endl;
      cout &lt;&lt; endl;
      cout &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; setprecision(2);
      cout &lt;&lt; "                               *** " &lt;&lt; average &lt;&lt; " ***" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>So this program was made to allow students to enter as many test scores as they want and the program will show them in ascending order and then will calculate the average of all test scores. It works wonderful until you enter a negative test score and then it throws the averaging process off. I can't seem to be able to make the program not accept the negative numbers. Any clues or hints would work wonders! Please and Thank You.</p>