arrays,rand,average

I am trying to combine a few functions in 1 program. I am first trying to create a n array of size 6 to generate random positive two digit numbers. Then I want to call on the array and take the average of the numbers in the output. Here is what i have so far but i have some errors, how can i call on the array function properly?


include <iostream>
using namespace std;

int main() {

int array[6], i, counter = 0;
srand(time(0));
for(i = 0; i<6; i++)
int x = rand() % 89 + 10;
cout << array[i]<< " " << endl;


int sum = 0;
int average = 0;
int array [i];
for (int i = 0; i < 6; i++)
sum+=array[i];
average = sum/6;
cout << "Average:" << average;
}





1) its #include
2) you need to include <random> (for srand() and rand()) and <ctime> (for time())
3) curly brackets after 1st for statemend and 1st cout.
4) curly brackets after 2nd for statement and before average = ....
5) int x = rand() % 89 + 10; should be array[i] = rand() % 89 + 10;
6) Do not declare array second time.
7) count variable isn't used and can be removed.
8) you miss return statement

EDIT: BTW you are generating numbers in range 10-98.
Last edited on
Topic archived. No new replies allowed.