Erray Expander

I am having difficulties with a program I have written.My program will compile, however, it does not make the numbers "expand" or double. I would appreciate if someone might be able to find out what I am doing wrong. The problem is:

Write a function that accepts an int array and the array's size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and intialize the unused elements of the second array with 0. The function should return a pointer to the new array.

And my code is:
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
//This program is used to accept an int array and the array's size as      arguments, and then creates a new
//array that is twice the size of the argument array.
#include <iostream>
using namespace std;

int* expandSize (int*, int);

int main()
{
	const int SIZE = 10;											//Number of elements
	int ary [SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};				//Used to hold numbers
	int* num = ary;													

	for(int index= 0;index<SIZE;index++)
		cout<<num[index]<<endl;
	

	num = expandSize(ary, SIZE);	//Used to assign num to the memory location of the return

	for(int index=0;index<SIZE;index++)
		cout<<num[index]<<endl;

	delete[] num;	//Used to delete memory
	num = 0;		//Used to point the unused elements of the second array with zero.

	return 0;
}
//**********************************************************************************************************
//The function expandSize accepts an int array and the array's size as arguments. The function then creates*
//a new array that is twice the size of the argument array.												   *
//**********************************************************************************************************
int* expandSize(int* arr, int size)
{
int* expandArray=new int[size * 2];

for (int index=0;index<size;index++)
expandArray[index]=arr[index];

for (int index=size;index<size*2;index++)
expandArray[index]=0;

return expandArray;
}
Your function conforms to the task description, so what's the problem?
It does not double the second set of numbers. They remain the same when I compile the program.
It does. It's just that you're only printing half of the new array.
Ok... I can't exactly pin point what you are referring to. Could you tell me what number line I need to work on then or what I need to correct? I apologize that I am so confused I have been working on this program for a couple days now and I simply cannot figure it out even after reading your advice.
Write SIZE*2 in line 20.
The name "index" should be shortened to "i", by the way.
Thank you for that, however, it is still not compiling right. It puts several zero's in it and a couple random numbers above the original numbers. I really appreciate your help and advice.
It compiles fine, otherwise you wouldn't see any output. The program itself is fine too.
You should post your new code, the output you get and just to be sure, the output you expect.
I'm sorry I did not mean to say it that way. I am just a little frustrated with this program right now.

The output I get when I run the program is: 12345678910123456789100000000000
The output I want the program to run is: 12345678910149162536496481100

Here is my new 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
//This program is used to accept an int array and the array's size as arguments, and then creates a new
//array that is twice the size of the argument array.
#include <iostream>
using namespace std;

int* expandSize (int*, int);

int main()
{
	const int SIZE = 10;											//Number of elements
	int ary [SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};				//Used to hold numbers
	int* num=ary;													

	for(int index=0;index<SIZE;index++)
		cout<<num[index]<<endl;
	

	num=expandSize(ary, SIZE);	//Used to assign num to the memory location of the return

	for(int index=0;index<SIZE*2;index++)
		cout<<num[index]<<endl;

	delete[] num;	//Used to delete memory
	num = 0;		//Used to point the unused elements of the second array with zero.

	return 0;
}
//**********************************************************************************************************
//The function expandSize accepts an int array and the array's size as arguments. The function then creates*
//a new array that is twice the size of the argument array.												   *
//**********************************************************************************************************
int* expandSize(int* ary, int size)
{
int* expandArray=new int[size * 2];

for (int index=0;index<size;index++)
expandArray[index]=ary[index];

for (int index=size;index<size*2;index++)
expandArray[index]=0;

return expandArray;
}
However, the output you expect doesn't match the task description.
Maybe you posted the wrong one?
Thank you for pointing that out to me. I think I am going crazy lol. I guess I read the problem wrong. You are right, and I appreciate all your help!

Thank you so much!
Topic archived. No new replies allowed.