I added comments. Read 'em
Code:
float average(int tarray[], int num);
int main()
{
int day,i;
float avgtemp,avghumid;
int hum[31], temp[31];
printf("How many days =>");
scanf("%i",&day);
printf("\n\n");
if (0<day&&day<=31)
{
for (i=0; i<day; i++)
{
printf("Enter temperature and humidity for day %i =>",i+1);
fflush(stdin);// See http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351
scanf("%d %d",&temp[i], &hum[i]);
}
avgtemp = average(temp,day);
avghumid = average(hum,day);
printf("\t\n\nAverage temperature = %.1f degC",avgtemp); // f was right here but type was int
printf("\t\nAverage Humidity = %.1f %%",avghumid); // same
}
else
{
printf("wrong input");
}
getch();// getch isn't a great way of stopping the conosle.
return 0;// Don't forget to return something either.
}
float average(int tarray[], int num)// changed return type to float
{
int i; // got rid of days
float avg; // changed type
int total=0;// assigned an initial value
avg=0;
for (i=0; i<num; i++) // was i<days, but num is passed into the function
{
total += tarray[i]; // can use the += operator.
}
avg=total/num; // changed days to num
// Might want to make this function return a float or double as division
// may cause floating point arithmitic.
return(avg);
}