I've been looking for a solution to this but haven't found anything that will help. I'm getting the following errors:
Implicit declaration of function 'sum' is invalid in C99
Implicit declaration of function 'average' is invalid in C99
Conflicting types for 'average'
Has anyone experienced this before? I'm trying to compile it in Xcode.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool
{
int wholeNumbers[5] = {2,3,5,7,9};
int theSum = sum (wholeNumbers, 5);
printf ("The sum is: %i ", theSum);
float fractionalNumbers[3] = {16.9, 7.86, 3.4};
float theAverage = average (fractionalNumbers, 3);
printf ("and the average is: %f \n", theAverage);
}
return 0;
}
int sum (int values[], int count)
{
int i;
int total = 0;
for ( i = 0; i < count; i++ ) {
// add each value in the array to the total.
total = total + values[i];
}
return total;
}
float average (float values[], int count )
{
int i;
float total = 0.0;
for ( i = 0; i < count; i++ ) {
// add each value in the array to the total.
total = total + values[i];
}
// calculate the average.
float average = (total / count);
return average;
}