Missing factor?

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.







#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;






}



I get this error message on the 6th line:

error: expected unqualified-id before ‘{’ token
Remove the semicolon at the end of this line:
 
int * expand (int numbers[], int size);

Topic archived. No new replies allowed.