Ok, I realize I just asked for help, but I am so confused right now. I have been working for the past hour on another problem (which is just an add on to the last one I posted about), and I know I am SOMEWHERE on the right track, but I just need a tad bit of guidance? My professor didn't give me much to go off of to find the average using arrays/loops, except the following model function:
Code:
double find_average(int * array, int size)
{
int sum = 0;
int i;
for(i = 0; i < size; i++)
{ sum += array[i]; } /* running total */
return sum/ sizeof(array)/sizeof(*array);
}
I need to find the average of all of the scores. This is what I have, and after is the errors I am getting.
Code:
# include <stdio.h>
/*prototypes*/
double find_average(double *score[], int size);
int main()
{
double score[5];
int i;
double average;
int size;
size=5;
score[0]= 81.4;
score[1]= 75.3;
score[2]= 90.0;
score[3]= 96.9;
score[4]= 85.6;
printf( "The grades are:" );
for (i=0; i < sizeof(score)/sizeof(*score); i++)
{
printf(" %.1lf", score[i]);
}
printf("\n");
printf("The average is: ");
average = find_average(*score, size);
printf("/n");
return 0;
}
/*methods*/
double find_average(double *score[], int size)
{
int sum = 0;
int i;
for(i = 0; i < size; i++)
{ sum += score[i]; }
return sum / (sizeof(score)/sizeof(*score));
}
Errors:
hw10test2.c: In function āmainā:
hw10test2.c:29: error: incompatible type for argument 1 of āfind_averageā
hw10test2.c:4: note: expected ādouble **ā but argument is of type ādoubleā
hw10test2.c: In function āfind_averageā:
hw10test2.c:42: warning: assignment makes integer from pointer without a cast
Once again, any help would be greatly appreciated! I hate asking for help, but I just can't figure this out for some reason. I have almost nothing to go off of (no instruction related to this specifically, just some vague instructions on passing techniques).
Thank you!