C programming return value odd -
i tried search everywhere, it's kind of difficult word, it's simple fix. when go through program supposed compute average rainfall year, comes out large number, however, thought may have been doing arithmetic wrong or had syntax error of sort, not case, when checked value function returned proper value.
#include <stdio.h> #include <string.h> void getdata(float *, float *); int main() { char state[2], city[81]; float rainfall[12], outputaverage, *paverage; printf("name here\n"); printf("please enter state using 2 letter abreviation: "); gets(state); printf("please enter city : "); gets(city); paverage = &outputaverage; (getdata(rainfall, paverage)); printf("%.2f", outputaverage); return (0); } void getdata(float *rainfall, float *paverage) { int i; float total; (i=0; i<12; i++) { printf("please enter total rainfall in inches month %d: ", i+1); scanf("%f", &rainfall[i]); total += rainfall[i]; } *paverage = total / 12; }
you need initialize total
float total = 0.0;
Comments
Post a Comment