Hello. I'm writing an awk script that looks at a .csv file and calculates the weighted grade based on the scores and categories in the file. I keep getting a fatal division by zero attempted error and I know what it means but I've been looking over the code for awhile and am not sure what is causing it. Here is the code that I have:
BEGIN{
FS = ","
print "Name\tPercent\tLetter"
a=0
}
{
if(a==0){
a+=1
}
else{
sum[$1] += $4
total[$1] += $5
students[$1]++
category[$2]++
}
}
END{
for (student in students){
Homework=(sum[$1"Homework"]/total[$1"Homework"])*0.10
Lab=(sum[$1"Lab"]/total[$1"Lab"])*.30
Final=(sum[$1"Final"]/total[$1"Final"])*.15
Quiz=(sum[$1"Quiz"]/total[$1"Quiz"])*.40
Survery=(sum[$1"Survey"]/total[$1"Survey"])*.05
total=Homework+Lab+Final+Quiz+Survey
}
printf "%s\t%.2f\t",student, total
if(total>=90 && total<=100)
print "A";
else if(total>=80 && total<90)
print "B";
else if(total>=70 && total<80)
print "C";
else if(total>=60 && total<70)
print "D";
else
print "E"
}