I think you're confused about what you're doing and what you want to do. What you want to do is use x and y as indices for printing out the elements of the array. What you're doing is echoing all numbers between x and y. This is what you want:
Code:
#include <iostream>
using namespace std;
void print(int array[], int x, int y);
int
main()
{
int array[] = {1,2,3,4,5,6,7,8,9,10};
int x, y;
cout<<"Enter two numbers: ";
cin>> x >> y;
cout<<"The elements in [x,y) are: ";
print(array, x, y);
cout<<endl;
}
void
print(
int array[],
int x,
int y
)
{
cout<< array[x];
while (++x != y) {
cout<<", "<< array[x];
}
}