我试图在任何地方搜索这个,但它有点难以用词,它很可能是一个简单的修复。基本上,当我通过我的程序应该计算一年的平均降雨量时,它会得出一个非常大的数字,但是,我认为这可能只是我做错了算术或语法错误某种,但事实并非如此,当我检查函数返回的值时,它是正确的值。
#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 the state using a two letter abreviation: ");
gets(state);
printf("Please enter the city : ");
gets(city);
pAverage = &outputAverage;
(getData(rainFall, pAverage));
printf("%.2f", outputAverage);
return (0);
}
void getData(float *rainFall, float *pAverage)
{
int i;
float total;
for (i=0; i<12; i++)
{
printf("Please enter the total rainfall in inches for month %d: ", i+1);
scanf("%f", &rainFall[i]);
total += rainFall[i];
}
*pAverage = total / 12;
}