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

#include<iostream>
#include<cmath>

// Function declarations
using namespace std;
void tableFill(int myArray[], int size);
int isSymmetrical(int myArray[], int size);
void printArray(int myArray[], int size);

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

    do {
        cout << "Enter the size of the array (integer) > ";
        cin >> temp_size;

        if ( temp_size <=0 ){
            cout << "*** that is not valid input ***\n";
        }
        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;

    int * myArray = new int [size];

    tableFill(myArray, size);
    printArray(myArray, size);

    if (isSymmetrical(myArray, size)){
        cout << "The array IS symmetrical.\n";
    }else{
        cout << "The array IS NOT symmetrical.\n";
    }

    return 0;
}

// ******************************************************************* //
//  This function will take an previously declared array and ask the   //
//  the user for integers to fill it with.                             //
// ******************************************************************* //
void tableFill(int myArray[], int size)
{
    int i;

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

        // Check to make sure the user entered an integrer
        /*
        while (floor(myArray[i]) != ceil(myArray[i])){
            cout << "**** That is not an integer! ****";
            cout << "Enter value for element " << i << " in the array > ";
            cin >> myArray[i];
        }*/
    }
    return;
}

// ******************************************************************* //
//  This fuction will determine is the given array is symmetrical      //
//  It returns true if symmetrical and false if the array is not sym.  //
// ******************************************************************* //
int isSymmetrical(int myArray[], int size)
{
    int is_sym = true;
    int i;

    for (i=0; i<=size/2 && is_sym == true; ++i){
        if (myArray[0+i] != myArray[(size-1)-i]){
            is_sym = false;
            //cout << i << ": ";
            //cout << myArray[0+i] << " != " << myArray[size-i] << "\n";
        }
    }
    return (is_sym);
}

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

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

