I'm trying to create an array that generates 20 random numbers from 0-9 using a certain random seed(which i have already), then calculates the average of the random numbers generated. I've gotten it to execute the array fine, but when i go to calculates the sum of the random numbers, it gives me back -16. I've looked at several different other things to try to help and they all have the same thing that i've got
for (i = 0; i < SIZE; i++) {
sum += num[SIZE];}
Can someone point out what im doing wrong here or else where in the program?
#include <iostream>
#include <cstdlib>
using namespace std;
int main() // Creates the array
{
srand(2622); // random seed
const int SIZE = 20;
int num[SIZE], i, sum = 0;
for (i = 0; i < 20; i++) {
cout << rand() % 10 << " : "; // generates random numbers 0-10
}
cout << endl;
for (i = 0; i < SIZE; i++) {
sum += num[SIZE];
}
cout << sum << endl;
return 0;
}