Program tweeking with arrays

What it does is ask the user to put numbers and then it will take the average.

Hey so i was wondering how would i be able to tell the program ignore a users input if he put a negative number it, just ignores it but solves for the numbers that are positive. Which means it would just ignore it and only solve for the ones to be averaged

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 #include <iostream>
using namespace std;

/**********************************************************************
 * Main well got lazy on creating different functions so I put everything
 * in main.
 ***********************************************************************/
int main()
{
   const int SIZE = 10;

   int grades [SIZE];
   int average;

   average = 0;

   for (int i = 0; i < SIZE; i++)
   {
      cout << "Grade " <<  i + 1 << ": ";
      cin >> grades[i];

      average = average + grades[i];
   }

   average = average / SIZE;
   cout << "Average Grade: ";
   cout << average;
   cout << "%" << endl;

   return 0;

}
Last edited on
Topic archived. No new replies allowed.