array problems

the code below is from a void function ,, it asks the user to enter 10 numbers
which go into an array then one more number to see if it is in the array

the first part works fine,, it outputs test the array as it being filled up
but when i test to see if the number is in the array for some reason it always changes the last index to the number im searching for

im sure its something simple but ive looked it over many times and cannot find a reason for why it does this ,, any help would be greatly appreciated

int a[9], number;

cout << "\n\nEnter 10 numbers, and then one more to see if its in the first list.\n";
for(int i = 0; i < 10;i++)
{
cout << "Enter a number:";
cin >> a[i];
cout << "\na index " << i << " is " << a[i] << "\n";
}

cout << "\nEnter one more number:";
cin >> number;

for(int i = 0; i < 10;i++)
{
cout << "\n TEST a index " << i << " is " << a[i] << "\n";
if(number == a[i])
{
cout << "\nThe " << number << " was in the array";
}
else
{
cout << "\nThe " << number << " was not in the array";
}
}
You have defined your array too small. You have allowed for only nine numbers. Either change the array size or your loop sentinel.
Topic archived. No new replies allowed.