Quote:
Originally Posted by akounga
Hi all,
Can somebody help me; i'm trying to write a script with the IF statement which reads 5 grades, calculates and displays the lowest, highest and the final letter grade;
I've written the IF statement which reads 5 grades.
My problem is to write the script which will calculate and display the lowest, highest and the final letter grade.
This's what i've written so far:
gradeA=90
gradeB=80
gradeC=70
gradeD=60
gradeF=59
...
fi
|
after you've read gradeA, ..., gradeF
...
here's what you can do to get the lowest and highest
grade among $gradeA, ..., $gradeF
# print lowest, highest grade
lowest=$gradeA
highest=$gradeA
for grade in $gradeA $gradeB $gradeC $gradeD $gradeF
do
if [ $lowest -gt $grade ]; then
lowest=$grade
fi
if [ $highest -lt $grade ]; then
highest=$grade
fi
done
echo "highest grade: $highest"
echo "lowest grade: $lowest"
echo "out of these grades: $gradeA, $gradeB, $gradeC, $gradeD, $gradeF"