Random Number Generator and Average Help!

Hey , i need to create a program that has has an array size of 20 and will generate 20 random numbers in it between 1-1000. Then I need to calculate the average of all the random numbers.

I have half of the code done ,but im lost on how to calculate the average of the random numbers.

And also could you please point out any way to help shorten my coding that will be helpfull :D
Here what I have:

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
34
35
36
37
38
39
//Assignment 17 Program 2
#include <iostream>
using namespace std;
int i;
int size[20];
int counter = 0;
int main()

{	

cout << "The Array Consists Of 20 Random Numbers: "<<endl<<endl;

//Random Numbers Generator

srand ( time(NULL) );
for (int j = 1;j<20;j++)
{
i = rand() % 1001;
if (i != i-1)
size[j]=i;
else
{
i = rand() % 1001;
size[j]=i;
}
}
for (int k = 1; k < 20 ; k++)
{
cout << size[k] << " "<<endl<<endl;
}

//Average Of Random Generated Numbers




system ("pause");
return 0;
}
To get the average, add all the numbers, and divide it by the count.
could you help me on how to do that?

I have no idea on how to do it.
Topic archived. No new replies allowed.