Lots of arithmetic problems!
You're dividing inside the inner loop - move it to just below the inner loop.
Also, sum = 0 needs to be moved just before the inner for loop for j, begins. (inside the for i loop, but outside the for j loop.
To average the HW, quizzes, and tests, you'll need to do the index "flip" trick on the inner for loop. Otherwise, you'll make an average for the rows, instead of the column, as you have already seen.
From looking at the code, i thought you were trying to get an average score for each student, but later saw you wanted an average for the class, for each test, etc.
This is completely untested for accuracy, and I have not looked at your assignment at all. The assignment is yours to handle. If you can't describe the programming problem here, I can't help you.
Code:
#include <stdio.h>
#include <stdlib.h>
void 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.0;
int i, j, r, c;
printf("\n\t HW1\t HW2\t Quiz1\t Quiz2\tMidterm\tFinal\t Total\t Grade\n"); //: Header://
for(i=0; i<15; i++)
{
sum = 0.0;
for (j=0; j<6; j++)
{
grade[i][j] = 50.0 + rand() % 50; //: generates random grade for each element in the 2d array://
sum = sum + grade[i][j];
}
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];
}
for(i=0; i<15; i++)
{
printf("\n");
printf("%d\t", i+1); //: prints the student ID number, (line numbers)://
for (j=0; j<6; j++)
{
printf("%6.2f\t", grade[i][j]);
}
printf("%6.2f\t ", total[i]);
ltrgrade(total[i]);
}
printf("\n\nAverage:"); //: Here for the sake of shiowing where I need it formatted://
//c = column, r = row. note how c & r are "flipped"
for(c = 0; c < 6; c++) {
for(r = 0, sum = 0; r < 15; r++) {
sum += grade[r][c]; // flipped here
//if(c== 6) printf("\t%4.2lf", grade[r][c]); //for debug only
}
average[c] = sum/15;
}
/*
This "flipping" of indexes is very common for scoreboards and
any summation of columns in a table - like here
*/
//average score for all students on 1 HW, Quiz, or Test
for(i=0;i< 6;i++)
printf("%6.2f\t", average[i]);
printf("\n\n\t\t\t press enter when ready");
i = getchar();
return 0;
}
That will get you started.
Remember to have a return "something", for every function that has a return type. If you don't want a return, then make it a void function. main() is the exception - it should always return 0 or "EXIT_SUCCESS" on a normal exit, or some other value, depending on the type of failure.