Grade program average problem
I've got everything printed an formatted as per the example in the attachment, but when the program runs, the values for average are all incorrect. Any ideas/solutions are welcome and appreciated :)
Code:
#include <stdio.h>
#include <stdlib.h>
char ltrgrade(double x)
{
if(x>=90)
printf("A");
else if(x>=80)
printf("B");
else if(x>=70)
printf("C");
else if(x>=60)
printf("D");
else
printf("F");
}
int main()
{
double grade[15][6];
double total[15];
double average[7];
double sum=0;
int a;
printf("\t HW1\t HW2\t Quiz1\t Quiz2\tMidterm\tFinal\t Total\t Grade\n"); //: Header://
for(int i=0; i<15; i++)
{
for (int j=0; j<6; j++)
{
grade[i][j] = 50.0 + rand() % 50; //: generates random grade for each element in the 2d array://
total[i] = .05f*grade[i][0]+.05f*grade[i][1]+.1f*grade[i][2]+.1f*grade[i][3]+.3f*grade[i][4]+.4f*grade[i][5];
sum=0;
sum = sum + grade[i][j] ;
average[j]= sum/15;
}
}
for(int i=0; i<15; i++)
{
printf("\n");
printf("%d\t", i+1); //: prints the student ID number, (line numbers)://
for (int j=0; j<6; j++)
{
printf("%6.2f\t", grade[i][j]);
}
printf("%6.2f\t ", total[i]);
ltrgrade(total[i]);
}
printf("\nAverage:"); //: Here for the sake of shiowing where I need it formatted://
for(a=0;a<7;a++)
printf("%6.2f\t", average);
printf("\n");
system("pause");
}