Vector problem

hi again here is what my program should do: the program ask the user to imput the size of an array then the program must create the array fillit it with random numbers and then output its content to the console. the program compiles but an error box appear as soon as the user imputs any size then it crash. here is my code:
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>	

using namespace std;

void PrintArray(vector<int>&array);
void RandomArrayFill(vector<int>&array);


void RandomArrayFill(vector<int>&array)
{
	int i=0;
	for(i=0;i<=array.size();i++)
	{
		array[i]= rand() % 101;
	}
}
void PrintArray(vector<int>&array)
{
	int i=0;
	for(i=0;i<array.size()+1;i++)
	{
		if(i==array.size())
		{
			cout <<array[i] << "}" << endl << endl;
			break;
		}
		cout << array[i] << ", " ;
		
	}
}

void main()
{
	int numero=0; 
	vector<int> bobby; 
	srand( time(0) );

	do
	{
	cout << "Enter the size of an array to create: ";
	cin >> numero;
	bobby.resize(numero);
	RandomArrayFill(bobby);
	cout << endl << endl << "Creating array and filling it with random numbers...";
	cout << "Array = {";
	PrintArray(bobby);
	}
	while(numero!=0);
	cout << "NULL Array" << endl;
}

hope you can help me figured out what the hell is going on thx in advance
ok i figured out the problem but i do not understand why. the problem was that the function filled inexisten indexes in the array. my question is a vector array of size 1 it has only one element rather than a common array who has 2 elements (0 and 1)?
here is my code:
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 #include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>	

using namespace std;

void PrintArray(vector<int>&array);
void RandomArrayFill(vector<int>&array);


void RandomArrayFill(vector<int>&array)
{
	int i=0;
	for(i=0;i<array.size();i++)
	{
		array[i]= rand() % 101;
	}
}
void PrintArray(vector<int>&array)
{
	int i=0;
	for(i=0;i<array.size();i++)
	{
		if(i==array.size()-1)
		{
			cout <<array[i] << "}" << endl << endl;
			break;
		}
		cout << array[i] << ", " ;
		
	}
}

void main()
{
	int numero=0; 
	vector<int> bobby; 
	srand( time(0) );

	do
	{
	cout << "Enter the size of an array to create: ";
	cin >> numero;
	bobby.resize(numero);
	RandomArrayFill(bobby);
	cout << endl << endl << "Creating array and filling it with random numbers...";
	cout << "Array = {";
	PrintArray(bobby);
	}
	while(numero!=0);
	cout << "NULL Array" << endl;
}

forget that i asked im a fool
Well at least talking through the problem among yourself helped you solve it ;o)
Topic archived. No new replies allowed.