#include <iostream>

// return pointer to location from function
double* maximum(double *a, int size)
{
    if (size == 0) return 0;

    // initialize both variables
    double* max_pos = a; // points to the value in a[0]
    double maxVal = *max_pos; // this is the starting max value
    std::cout << "max_pos = " << max_pos << " (" << maxVal << ")" << std::endl;

    for(int i = 1; i < size; ++i){
        if (a[i] > maxVal){
            max_pos = &a[i];
            maxVal = *max_pos;
            std::cout << "max_pos = " << max_pos << " (" << maxVal << ")" << std::endl;
        }
    }

    // return address
    return max_pos;
}

int main()
{
    const int arrSize = 5;
    double myarr[arrSize];

    std::cout << "Input " << arrSize << " floating point values for your array" << std::endl;

    for(int i = 0; i < arrSize; ++i){ // loop to input values
        std::cin >> myarr[i];
    }

    for(int j = 0; j < arrSize; ++j){
        std::cout << "Location for " << myarr[j] << " = " << &myarr[j] << std::endl;
    }

    double* maxNum = maximum(myarr, arrSize);
    std::cout << "maxNum = " << maxNum << " (" << *maxNum << ")" << std::endl;

    return 0;
}