//--------------------------------------------------------------------
// arrpass.cpp 
// program that illustrates passing of arrays as parameters
//--------------------------------------------------------------------

// Passes an array to a function and doubles the values of the array.

#include <iostream.h>

const int MAX_NUM_VALS = 20;   // Max number of data values
const int MAX_PER_LINE = 5;    // Max values per line to display

void inputValues ( int data[], int count );
void doubleValues ( int data[], int count );
void displayValues ( int data[], int count );

void main ()
{
    int numVals,                // Actual number of values to process
        value[MAX_NUM_VALS];   // Array of integers

    // Prompt the user for the number of data items.
    cout << endl << "Enter the number of values to process: ";
    cin >> numVals;

    // Read in the data.
    inputValues(value,numVals);

    // Double the value of each data element.
    doubleValues(value,numVals);

    // Display the data.
    cout << "Data doubled:";
    displayValues(value,numVals);
    cout << endl;
}

//--------------------------------------------------------------------

void inputValues ( int data[], int count )
// Read values into an array.
{
    int j;
    cout << "Enter the data: ";
    for ( j = 0; j < count; j++ )
        cin >> data[j];
}

//-------------------------------------------------------------------

void doubleValues ( int data[], int count )
// Double the values in the array.
{
    int j;
    for ( j = 0; j < count; j++ )
        data[j] = data[j] * 2;
}

//--------------------------------------------------------------------

void displayValues ( int data[], int count )
// Display the values in the array.
{
    int j;
    for ( j = 0; j < count; j++ )
    {
        if ( j % MAX_PER_LINE  == 0 )
            cout << endl;
        cout << data[j] << " ";
    }
}