I tried using the code David show to average a set of scores in an array.
#include <stdio.h>
#include <cs50.h>
float average (void);
int main(void)
{
int n = get_int("Total scores: ");
int scores[n];
for(int i = 0; i < n; i++)
{
scores[i] = get_int("Score %i\n", i+1);
}
printf("Average %f", average);
}
float average(int n, int scores[])
{
int sum = 0;
for(int i = 0; i < n; i++)
{
sum = sum + scores[i];
}
return sum / (float) n;
}
This is the error I get.
arrayPractice2.c:14:26: error: format specifies type 'double' but the argument has type 'float (*)(void)' [-Werror,-Wformat]
printf("Average %f", average);
~~ ^~~~~~~
arrayPractice2.c:17:7: error: conflicting types for 'average'
float average(int n, int scores[])
^
arrayPractice2.c:4:7: note: previous declaration is here
float average (void);
^
I never define average as a double so I don't understand why it says there is a conflict. Any help you could provide would be greatly appreciated.