Does the array fine but when it does the function it wont work, if anyone can help that would be great!

#include <iostream>

using namespace std; 
void reverse(int a[10], int size) 
{
   
    for (int j=0; j<size/2; j++) {
        int temp = a[j];
        a[j]     = a[size-j-1];
        a[size-j-1] = temp;
    }
    return;
}

int main()
{	
	int values;
    int size;
    int a[10];
	
       for(size = 0; size < 10; size++)
       {
               cout << "Please input the a max of 10 numbers and then type 00(doubel zero) to stop: " << endl;
               cin >> values;
               if(values == 00)
               {
                   cout << "You entered a double zero " << endl;
                   cout << "size of Array is " << size << endl << endl;
                   break;
               }
               a[size] = values;
	   }
	    cout << "Youve inputed the following numbers: " << endl;
		for(int i = 0; i < size; i++)
       {
		   cout << a[i] << "reverse of them: " << reverse(a[10], size) << endl;  
       }
		

	return 0;
}

Recommended Answers

All 3 Replies

you are calling reverse inside of the for loop, you only need the array to be reversed once so call it outside of the for loop

if(values == 00) This will not work as written. Values is an integer variable and I believe this will simply register as 0. You'll have to use another sentinel value or take in input as a string and convert it to int.

Also, your function returns void so attempting to use it with << is causing a problem. You need to output the old array before the function call and then print out the new version of a that has been changed by pointer.

I got it now thanks

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.