You invoked undefined behavior by
- using out-of-range array subscript.
- using value of uninitialized variable
sum having automatic storage duration, which is indeterminate.
The line sum += temp[25]; should be sum += temp[i];,
and the loop condition should be i < 25 or i < (int)(sizeof(temp)/sizeof(*temp)) instead of i <= 25.
Also sum have to be initialized.
Bisides of the undefined behavior, your program has following problems:
- What
get_value() returns is thrown away.
get_value() has unused and seems meaningless arugment temp_random.
- Functions are used before they are declared.
get_value() won't return 100 because rand()%40 will be only numbers between 0 and 39, inclusive.
Also note that the semicolon fter the block that belongs to the for loop is not needed. (This is not harmful though)
Your code should be like this:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define GENERATE_NUM 25
#define GENVALUE_MIN 60
#define GENVALUE_MAX 100
int get_value(void);
int main (void) {
int temp[GENERATE_NUM], i, sum = 0;
srand( (unsigned) time(NULL) );
for (i=0; i < GENERATE_NUM; i++) {
temp[i] = get_value();
sum += temp[i]; //Eventually will be added together to find avg
}
return 0;
}
int get_value(void) {
return((rand() % (GENVALUE_MAX - GENVALUE_MIN + 1)) + GENVALUE_MIN);
}