Use keyboard to enter size of array for both - >string and int arrays

The following code does not compile - I need to enter the array size via the keyboard for both a string and int array. The number you enter must apply to both arrays, string and int. ANY idea on how to fix - Newbie?

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
 int main()
{
	int SIZE;
	string array_string[];
	int num1[];

	// Enter array size
	cout << "Enter array size" << endl;
	cin >> SIZE;

	// array size for both string and int.
	array_string[SIZE];
	num1[SIZE];

	// populate string array 
	for (int index = 0; index <= SIZE; index++)
	{
		cout << "Enter string arrary and press return :" << (index + 1) << endl;
		getline(cin, array_string[index]);
	}
	cout << endl;

	// verify array elements just entered
	for (int index = 0; index <= SIZE; index++)
	{
		cout << "Names entered were: " << array_string[index] << endl;
	}

	// 
	// pupulate int array
	for (int index = 0; index <= SIZE; index++)
	{
		cout << "Enter int numbers and press return :" << (index + 1) << endl;
		cin >> num1[index];
	}
	cout << endl;

	// verify array elements just entered
	for (int index = 0; index <= SIZE; index++)
	{
		cout << "The Intergers you entered were: " << num1[index] << endl;
	}
	system("pause");
	return 0;
} 
Last edited on
The number you enter must apply to both arrays, string and int. ANY idea on how to fix

Assuming you can't use std::vector you must use dynamic memory (new/delete) to allocate the memory for the arrays after you get the size from the user.


Topic archived. No new replies allowed.