PDA

View Full Version : Conflicting types in array function declaration



mmvanbesouw
06-22-2008, 11:02 PM
I know this is an elementary assignment, but I'm new to this. I'm writing a program w/two functions, the first generates 10 random numbers, the second finds their average. The problem I'm having is with declaring the random function. I keep getting the error "Conflicting types for random". I don't see what my error is though. I get the error in the function declaration as well as in the function itself. Here's my code, which I think is good...does anyone have any suggestions?

Thank you very much!


#include <stdio.h>
#include <stdlib.h>
#define ARY_SIZE 10

// Function Declarations
void random (int ary[]);
double average (int ary[]);

int main (void)
{
// Local Declarations
int ary[ARY_SIZE];

// Statements
random(ary);
printf("The average of the random numbers is: %.1lf\n", average(ary));

return 0;

} // main

/* ***************************** Random ********************************
This function fills the arry with random integers, between 10 and 20.
*/

void random (int ary[])
{
// Local Definitions
int range = (20 - 10) + 1;
int i;

// Statements
for (i = 0; i < ARY_SIZE; i++)
ary[i] = rand() % range + 10;

return;
}

/* *************************** Average **********************************
This function takes the random numbers from the random function and finds
their average. It returns it to the main function as a double.
*/

double average (int ary[])
{
// Local Definitions
int i;
int sum = 0;

// Statements
for (i = 0; i < ARY_SIZE; i++)
sum += ary[i];

return ((double)sum/ARY_SIZE);
}

oracleguy
06-22-2008, 11:57 PM
random might be already defined in the header files you are including, try changing the function name and see if the error goes away.

mmvanbesouw
06-23-2008, 02:15 AM
Thank you so much! I've spent two days trying to figure this out, and your suggestion worked perfectly. Thanks again!