Hi, my program needs to return the max value of an array given the input of the user. I believe I am pretty close to getting it to work, but I know I have a few errors. Calling functions still confuses me and I think that is where I am going wrong.
Here is my code:
Code:
#include<stdio.h>
int findLargest(double *array, int arrayLength);
int main()
{
double nums[80];
int pos;
for (pos=0; pos<10 && nums[pos]!=EOF; ++pos)
{
printf("Enter in a number or EOF to quit: ");
scanf("%lf", &nums[pos]);
}
for (pos=0; pos<10; ++pos)
{
printf("%lf\n", nums[pos]);
}
double maximum = findLargest(nums, pos);
int OS;
if(pos<=0)
printf("There is no maximum element,\n");
else
printf("The maximum value is %lf at offset %d\n", maximum, OS);
}
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[1];
}
}
return max;
}
Any help or suggestions would be greatly appreciated!!