Suming up array gives error C programming -


i have write program calculates number of hours worked within specific period , prints total number of hours, average length of day , itemisation of hours entered. first, program must ask how many days of working hours shall entered (max 30 days). after this, program asks daily working hours. program output shall have 1 decimal place of precision.

the error getting when adding values total hours worked goes above 100000, not sure why.

here code

#include<stdio.h>     int main()   {     float hours[30];     float total;     int day;     int ;     float avg;     int j;      printf("the program calculates total hours worked during \na specific period , average length of day.\n\n");     printf("how many days:");     scanf("%d",&day);      for(i=0; i<day; i++){      printf("enter working hours day %d:",i+1);      scanf("%f",&hours[i]);      total += hours[i];     }     avg = total/day;      printf("total hours worked: %.1f\n", total);     printf("average length of day: %.1f\n", avg);     printf("hours entered:");       for( j = 0; j < day; j++){           printf("%.1f\t", hours[j]);       }  } 

error message compiler error message

total not initialized here. need set 0:

float total = 0; 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -