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;

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;
               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;
7 Years
Discussion Span
Last Post by blind122

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.

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.