read and understand the code you've been given, and learn from it. |
That's fair, up to a point. Though I'd be tempted to rewrite most of it, at the very least I would change the function signatures so that the array size is one of the parameters passed, rather than depending on the global X.
For example the input might look like this:
1 2 3 4 5 6 7 8 9 10
|
void inputFunc(int array[], int size)
{
cout << "Please enter " << size << " integer elements of an array. " << endl;
for (int count = 0; count < size; ++count)
{
cout << "array[" << count << "]: ";
cin >> array[count];
}
}
|
Then it could work for any array, regardless of size.
Though I'm not sure how helpful this is - it makes the code cleaner and more re-usable, but doesn't directly solve the problem.
An alternative would be to change the inputFunc to handle both arrays,
|
int inputFunc(int array1[], int array2[] );
|
and that might be what is expected.
Because the code for each array is very similar, this function could then call the version I suggested (maybe with a changed name) rather than duplicating the code.