#! /bin/bash

echo -e "\nWelcome to Grade Calculator at [`date`]"

echo -e "\nPlease enter number grades for the students on one line like"
echo -e "\n23 57 99 100\n"

declare -i stunum=1 n1 n2 n3 n4 sum avg N slimit

echo -ne "\nNumber of students : "
read N

# If you want to compute grades for N students, the slimit in while condition
# below should be (N+1).
#
# This is required because in our logic we are starting with initial value of
# stunum as 1 and using less-than comparison in the while condition below.

slimit=N+1

while [ $stunum -lt $slimit ]
do
	echo -ne "Student #$stunum : "

	# Read the four number grades.
	read n1 n2 n3 n4

	# Compute the average of input number grades.
	sum=n1+n2+n3+n4
	avg=sum/4

	echo -n "Average = $avg, Grade ="

	# Compute the corresponding letter grade now.
	if [ $avg -lt 65 ]
	then
		echo -e " F\n"
	elif [ $avg -lt 70 ]
	then
		echo -e " D\n"
	elif [ $avg -lt 80 ]
	then
		echo -e " C\n"
	elif [ $avg -lt 90 ]
	then
		echo -e " B\n"
	else
		echo -e " A\n"
	fi

	# Increment the student number.
	stunum=stunum+1
done
