Help about list<>

Can anyone help please.
i am creating a code will randomly create the list of N integers (from 4 – 56).
The value N will be input by the user.
But when i run this code, it have same amount of zero as the user input.

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>
#include <list>
#include <time.h>
#include <stdlib.h>
using namespace std;


int main()
{
	int N;
	cout<<"Enter the value of N "<<endl;
	cin>>N;
//	
	list<int>First;
	list<int>Second(N);
	list<int>::iterator it_1;
	
	srand(time(NULL));
	
	for(int i=0; i<5; i++)
	{
		int x = 4+rand()%52;
		Second.push_back(x);
	}
    
   for ( it_1=Second.begin(); it_1 != Second.end(); it_1++)
    cout << *it_1 << ' ';

	
	
	return 0;
	
}
list<int>Second(N); This is why.

If N is equal to 5. You create a list, called Second of size 5, and I guess it initializes them all to 0.

1
2
3
4
5
for(int i=0; i<5; i++)
	{
		int x = 4+rand()%52;
		Second.push_back(x);
	}


Why does this for-loop run 5 times? Shouldnt it run N times? And since you're filling the list here with N integers, there is no need for list<int>Second(N); Just change it to
list<int>Second;
it's work , thank you so much
Topic archived. No new replies allowed.