Clearification on array

Does this successfully assign the random values to the array?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

#include <iostream>
#include <cstdlib>	// for rand and srand functions
#include <ctime>
using namespace std;

int main()
{

	int num = 0;
	int ray [30] = {num}; 
	
	srand(1);

	for (int i = 0; i < 30; i++)
	{
		num = rand() % 100 + 1;
		cout << num << " ";
	}

	
	return 0;
}
No, you are still overwriting num every loop. By the way, you can just keep posting in your old topics...no need to make new ones.
to assign something to the elements off the array, you use the assignment operator '='

ray[ i ] = some_value;
Topic archived. No new replies allowed.