Help with understanding problem(s)

Hello everyone, this is my first time using this forum. I really need help with my homework. I currently can't compile my work. I had to download a 4gb extra something for VS 2015. Here are two things of my homework I can't figure out the problems too.

Problem #1 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 initialize the unused elements of the second array with 0. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named data into an array. The program then passes the array to your array expander function, and prints the values of the new expanded array on standard output, one value per line. You may assume that the file data has at least N values.

Prompts And Output Labels. There are no prompts for the integer and no labels for the reversed array that is printed out.

Input Validation. If the integer read in from standard input exceeds 50 or is less than 0 the program terminates silently.

:

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
55
56
57
58
59
60
61
#include <fstream>
#include <iostream>
using namespace std;

int * expand (int numbers[], int size);
{
	int* bigger = new int[size * 2];
	for (int i=0, i < size * 2, i++)
	{
		if (i < size)
			
		bigger [i] = numbers[i]
			
			else 
			
			bigger[i] = 0;
	
			return bigger;
		
int main()
{

	int N=0;
	cin >> N;
	
	if (N<0 || N>50)
		return -1;
	
	int * myarray = new int[N];
	
	ifstream ifile("data");
	
	for (int i =0; i < N; i++)
		
	{
		
		ifile >> myarray[i];
	}
	
	ifile.close();
	
	int* larger = expand(myarray,N);
	
	for (i=0; i < N * 2; i++)
	{
		
	cout << larger[i] << endl;	
		
	}
	
	delete[] myArray;
	delete[] larger;
	

	
	
	
	
}

} 
Last edited on
large code should go in code blocks <> on the side of the editor.
also, can you ask a better question? If it does not compile, what is the error??

We like to help people, but its a big pain to have to copy your code and compile it to try to figure out what the question even IS.
Sorry about that, I updated it with the correct problem as well. I think I'm missing something.

And I'm using a different my school's version of Visual Studio, that one compiles.
It's mostly correct, just a couple of errors.

1. In expand(), you don't terminate the function with }, it's misplaced to the end of the file.
2. Also, expand() doesn't return the new array.
Topic archived. No new replies allowed.