Array

I need help with my array. It is supposed to take ten values and switch the order of them.
# include <iostream>

using namespace std;

void userInput(int[], int);
void reverseArray(int[], int);

int main()
{
const int arraysize = 10;
int userArray[arraysize];
userInput(userArray, arraysize);

reverseArray(userArray, arraysize);

system("pause");
return 0;

}


void userInput(int userArray[], int arraysize)
{

cout<<"pleaser enter ten numbers"<<endl;
for(int index = 0; index < arraysize; index++)
{
cout<<"please enter value "<<(index+1)<<": ";
cin>>userArray[arraysize];
cout<<endl;
}
}

void reverseArray(int userArray[], int arraysize)
{
for(int counter = arraysize; 0 < counter; counter--)
{
cout<<"value number"<<counter<<" :";
cout<<userArray[counter - arraysize]<<endl;
}
}
Hi randomperson27,

you have a bug in your function userInput. When you do the cin, you currently give userArray[arraysize] while it should be userArray[index]
Hi randomperson27, I've found a few mistakes, one of them pointed out by aleonard and the others are in the function reverseArray:

1
2
3
4
5
for (int counter = arraysize - 1; 0 <= counter; counter--)
{
   cout  <<  "value number"<<arraysize - counter  <<  " :";
   cout  <<  userArray[counter - arraysize]  <<  endl;
}


The reason you must decrement the array by -1 is that your array has 10 positions but it goes from 0 to 9;

sorry for my bad english.
Last edited on
Topic archived. No new replies allowed.