Code:

I must be having a bad day but I am getting the wrong values for total. total+=sum should store the last value, correct. sum0=21,sum1=30.3 etc. I am storing it and adding it them together in total. However I keep getting701.80 and I need 271.9. What is the deal here. It is add up every number on each line over and over?

Code:

#include <stdio.h>
#define MAXNUMBER 10
void addfloat(float * array1, float * array2);
int main( )
{
float array1[MAXNUMBER] = {10.2,12.8,11.9,18.3,19.5,29.8,19.4,15.4,13.6,13.8};
float array2[MAXNUMBER] = {11.2,17.5,12.6,13.1,11.3,19.3,9.4,5.4,3.6,3.8};
addfloat(array1, array2);
return 0;
}
void addfloat(float * array1,float * array2)
{
int i;
float sum[MAXNUMBER];
float total[MAXNUMBER];
for (i=0; i < MAXNUMBER; i++)
{
sum[i] = array1[i] + array2[i];
total[i]+= sum[i];
printf("%4.1f + %4.1f = %4.1f\n",array1[i],array2[i],sum[i]);
}
printf("-----------------------\n");
printf("TOTAL:%14.3f",total[i]);
}