int *reverse(const int *, int);

int *temp;
temp = reverse(arr1,N);

int *reverse(const int *arr1, int N)
{
int *arr2;
arr2 = new int[N];

for(int count = 0; count < N;
count++)
{
for(int index = (N-1); index <=
0; index--)
arr2[count] = arr2[index];
}
return arr2;
}

I need to return a pointer but I am returning junk, I got the algorithm from the textbook.

You may need to "malloc" instead of just "new", which is an automatic variable that disappears when you quit the method.

Post again if that still does not work.

Or perhaps, arr2 contains garbage to start. It was never initialized, so there is nothing to reverse.

What does arr1 do? Is it supposed to be an array that you are reversing?

K I have gotten it to work in visual c++ by getting rid of the inner loop but it doesn't work on myprogramminglab so I don't know what else to do. The problem was extensive as well as the entire program, it works up until this function.

whole problem, whole program sorry...

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.

#include<iostream>
#include<fstream>
using namespace std;

int *reverse(const int *, int);

int main()
{
int N;
cin >> N;
if(N > 50 || N < 0)
exit(0);

int *arr1 = new int[N], index;

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

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

There are a few issues with the code that could be causing the problem. Let's go through them step by step:

1. In the reverse function, you are allocating memory for arr2 using the 'new' keyword, which is correct. However, you are not initializing the elements of arr2. This means that the values in arr2 could be garbage, leading to unexpected results. To fix this, you should initialize the values of arr2 to match the values of arr1 before performing the reverse operation. You can do this with a simple for loop:

```cpp
for(int i = 0; i < N; i++) {
arr2[i] = arr1[i];
}
```
2. The logic inside the for loop for reversing the array is incorrect. You have a mistake in your inner loop condition. The condition `index <= 0` should be `index >= 0` to properly loop through the array indices in reverse order. Also, you need to swap the elements of arr2, rather than assigning the same value. The corrected code looks like this:

```cpp
for(int count = 0; count < N; count++) {
for(int index = N-1; index >= 0; index--) {
arr2[count] = arr1[index];
}
}
```
3. Lastly, in the main code, you are not passing the values of the original array (arr1) and the size (N) correctly to the reverse function. Instead of passing the variables, you are passing uninitialized pointers (arr1 and N). To fix this, you need to pass the values of arr1 and N to the function as arguments:

```cpp
int *temp;
temp = reverse(arr1, N);
```
Overall, with these corrections, your reverse function should work correctly and return the reversed array. Make sure to free the memory allocated for arr2 when it is no longer needed using the `delete[]` keyword to avoid memory leaks.

```cpp
delete[] temp;
```