I just get confused with exactly how to get what I want out of the function.
Okay so I have fixed up most of what I need, the only part I really don't get right now is how to use pointers properly here. I need to get the values for both max and offset from my function into main and print them in my printf statement. How do I do this?
This is my newer code:
Code:
#include<stdio.h>
int findLargest(double *array, int arrayLength);
int main()
{
double nums[80];
int pos;
for (pos=0; pos<10; ++pos)
{
printf("Enter in a number or EOF to quit: ");
if(scanf("%lf", &nums[pos])<=0)
break;
}
double maximum = findLargest(nums, pos);
if(pos<=0)
printf("There is no maximum element.\n");
else
printf("The maximum value is %lf at offset %d\n", maximum, pos);
}
int findLargest(double *array, int arrayLength)
{
if (arrayLength <= 0)
return -1;
int offset=0;
int i;
double max = array[0];
for (i=0; i<arrayLength; ++i)
{
if (max < array[i])
max=array[i];
offset=i;
}
return offset;
}