Problem: write a function that returns a pointer to the maximum value of an array of double.
I have written the code that return the maximum, but I don't know how to turn it into a pointer and return it =.=

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

const double * maximum(const double a[], int size);

const double * maximum(const double a[], int size)
{
    double * result;
    double biggest = 0;
    if (size == 0) return 0;
    else{
        for(int i = 0; i < size; i++){
            if(a[i] > biggest) biggest = a[i];}}
    return result;
}

You need to add anothe integer to keep track of the loop counter when the value of biggest is changed so that the program knows which array element contains the largest value. Then you can just simply return return &a[bignum]; where bignum is whatever you want to name the new integer.

thanks =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.