The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 07-02-2009
dsptl dsptl is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 9
AWK Help (New to UNIX)

Write a script to calculate the average score and assign a letter grade for each student, also compute the average score for every test (the source data is in the file “grades”). Output all students’ name, scores, and grades in descending order of the average score. Note: please save the output to the file “finalgrades”.
Contents of source data file (grades):
Peter:90:80:70
Alice:79:89:69
David:99:79:89
The final letter grade will be determined based on the following criteria:
A: 90 and above; B: 80 thru 89; C: 70 thru 79; D: 60 thru 69; E; 50 thru 59; F: <50.
Output (finalgrades)



so far i have:


Code:
BEGIN{ print "Name   Test1   Test2   Test3   Average   Grade"}
{average=($2+$3+$4)/3;
grade="F"
if (average<50)
grade="E"
if (average<60)
grade="D"
if (average<70)
grade="C"
if (average<80)
grade="B"
if (average<90)
grade="A"
if (average<100)
printf("%-8s%-8d%-8d%-8d%-8d%-8d\n",$1,$2,$3,$4,average,grade)}


but grade is not working either

please help