EDIT MY CODE It just doesnt work Here is the question and my
EDIT MY CODE: It just doesn\'t work. Here is the question and my code is below it.
Question:
9.10: Reverse Array
 Write a function that accepts an int array and the array ’s size as arguments . The function should create a copy of the array , except that the element values should be reversed in the copy. 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 the your reverse array function, and prints the values of the new reversed 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.
My Code:
#include<iostream>
 using namespace std;
{
    int arr1[size];
    cout<<\"array in reverse order is\"<<endl;
    for(int i=1;i<size+1;i++)
    {
        arr1[i]=arr[size-i];
        cout<<arr1[i]<<endl;
    }
 
 }
 int main()
 {
    int size;
    cout<<\"Please enter the size of the array\"<<endl;
    cin>>size;
    if ((size<0) || (size>50))
    {
    while(1)
     {
     cout<<\"not valid. re-enter again\"<<endl;
     cin>>size;
     }
    if(size>0 && size<51)
    break;
    }
 }
    int arr[size];
    for(int i=0;i<size;i++)
    {
        arr[i]=i;
    }
    reverse(arr,size);
 }
Solution
here is the code and please let me know if any errors occurs and make sure i will modify then
#include<iostream>
#include<fstream>
using namespace std;
int *reverse(const int *, int);
int main()
{
int N;
N=10;
cin >> N;
if(N > 50 || N < 0)
exit(0);
int *arr1=new int[N];
int index;
for(int i=0;i<N;i++)arr1[i]=i;
fstream datafile;
datafile.open(\"data.txt\", ios::in | ios::out);
for(index = 0; index < N; index++)
{
datafile >> arr1[index];
}
int *temp;
temp = reverse(arr1,N);
for(index = 0; index < N; index++)cout << temp[index] << endl;
system(\"PAUSE\");
}
int *reverse(const int *arr1, int N)
{
int index = N-1;
int *arr2;
arr2 = new int[N];
for(int count = 0; count < N; count++)
{
arr2[count] = arr1[index];
index--;
}
return arr2;
}



