I'm wondering if I'm using the correct variable types or not. I'm supposed to use only floats and ints as far as I'm aware. I know its printing the "divide by 4" part because in the function I switched it to divide by 5 and it printed "5.0000". If I make "result" an int, it obviously strips the answer of the decimal points, but it still gives me the correct average and not "4". Why is it storing "4.0000" in the result variable instead of the answer?
void main(void)
{
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD;
// stop watchdog timer\
srand(time(NULL));
int val1 = (rand()%100);
int val2 = (rand()%100);
int val3 = (rand()%100);
int val4 = (rand()%100);
printf("%d\n",val1);
printf("%d\n",val2);
printf("%d\n",val3);
printf("%d\n",val4);
printf("%f\n",average4(val1, val2, val3, val4));
}
float average4(int val1, int val2, int val3, int val4){
float result;
result = (val1 + val2 + val3 + val4)/4;
return result;
}