Greetings.

Here's a sample template for finding MAX:

Code:

// calculate the zero-based offset of 'index'
template <typename type>
unsigned mem_pos(type * first, type * index) {
return (unsigned)((unsigned)index -(unsigned)first)/ sizeof(type);
}
// return a pointer to the MAX element
template <typename type>
type *
max(type data[], type * end) {
type * index, max = *data;
for(index = data; data != end; ++data)
if(*data > max)
index = data;
return index;
}
template <typename type>
type
max_value(type data[], type * end) {
return * max<type>(data, end);
}
// return the actual zero-based index of the MAX element
template <typename type>
unsigned
max_index(type data[], type * end) {
return mem_pos<type>(data, max<type>(data, end));
}
int main()
{
double mem[100], * input = &mem[-1];
puts("Enter up to 100 doubles, '0' to exit.");
do{
cin >> *(++input);
}while(*input != 0 && input != mem+100);
unsigned index = max_index(mem, input);
cout << endl << mem_pos(mem, input)
<< " numbers entered." << endl
<< "Maximum : " << mem[index] << endl
<< "Position : " << index << endl;
return getch();
}