I got the first part of my code from my teacher, its how the function should be done, I am just have trouble with what to put for my cin statments as, none of them work. Please help.

#include <iostream>

using namespace std;

void reverse(int* a, int n) 
{
    int* head = a;     // pointer to first element
    int* tail = a+n-1; // pointer to last element
    while (head < tail) 
	{      
        int temp = *head;
        *head  = *tail;
        *tail  = temp;
        head++;
        tail--;
    }
    return;
}
int main()
{
	int n;
	int a;
	
	cin >> a;
	cin >> n;

	cout << reverse(a,n);
return 0;
}

Recommended Answers

All 2 Replies

Your main() needs to declare an ARRAY of int's.

Then have a loop to fill the array.

Reverse it, then print it (another loop)

yeah this is basically all wrong:S

commented: In what wy was this post useful? -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.