I want to find the Grand Total by finding from the unit*price, but it gets 0.00, although it should be 12,640.00 so does anybody know how I can do this?
Here is the code
#include <stdio.h>
int main()
{
    FILE *in;
    char id[20][15];  // 20 persons   
    char des[20][15];
    int unit[30];
    float price[30];
    float sum = 0.0, total = 0.0;
    int i=0, j;
    in = fopen("price.txt", "r") ;
    if ( in == NULL )
    {
        printf( "Could not open file test.c" ) ;
        return 1;
    }
    while(!feof(in))
    {
        fscanf(in, "%s %s %d %f", &id[i], &des[i], &unit[i], &price[i]);
        i++;
    }
    printf("No. ID Descripton Price/Unit Unit Total Amount\n");
    for(j=0; j < i ;j++)
       printf("%d. %s %s %d %0.2f %0.2f \n",j, id[j], des[j], unit[j], price[j], unit[j]*price[j]);
    sum = unit[j]*price[j];
    total += sum;
    printf("Grand Total %0.2f",total);
    return 0;
}
 
     
    