// ************************************************************ //
//  Jeff Balsley                                                //
//                                                              //
//                                                              //
// ************************************************************ //
//  Known bugs:                                                 //
//                                                              //
// ************************************************************ //
//  to compile:  g++ -lm ass3.1.cpp -o ass3.1                   //
//                                                              //

#include<iostream>
#include<cmath>
using namespace std;

void tableFill(double myArray[], int size);
void printArray(double myArray[], int size);

int main()
{
    double temp_size;     // size of array
    int size;             // size of array

    do {
        cout << "Enter the size of the array (integer) > ";
        cin >> temp_size;
        if ( temp_size <=0 ){
            cout << "*** that is not valid input ***\n";
        }
        // *** Error checking *** //
        //cout << "floor(temp_size) = " << floor(temp_size);
        //cout << " ceil(temp_size) = " << ceil(temp_size);
        if ( floor(temp_size) != ceil(temp_size) ){
            cout << "*** that is not valid input ***\n";
        }
    } while ( (temp_size <=0) || ( floor(temp_size) != ceil(temp_size) ) );

    size = (int)temp_size;

    double * myArray = new double [size];

    tableFill(myArray, size);
    printArray(myArray, size);
    return 0;
}

// ************************************************************* //
//  This function fill the array with user input                 //
// ************************************************************* //
void tableFill(double myArray[], int size)
{
    int i;

    for (i=0; i<size; ++i){
        cout << "Enter value for element " << i << " in the array > ";
        cin >> myArray[i];
    }
    return;
}

// **************************************************************** //
//  This function will print out any array that is passed to it     //
//  This will be used for error checking                            //
// **************************************************************** //
void printArray(double myArray[], int size)
{
    int i;

    for (i=0; i<size; ++i){
        cout << "myArray[" << i << "] = " << myArray[i] << "\n";
    }

    return;
}
