Saturday 23 May 2020

Shell script to accept student test marks and find the result

Write a shell script to accept student information like name, class and 3 subject marks. Calculate the total and average. Result will be displayed based on average. If avg >=90 (Distinction), avg >=60 and avg<90 (First class), avg>=35 and avg<=59(Second class), avg <35 (Fail).


Program
echo "enter name"
read name
echo "enter class"
read class
echo "enter marks of 3 subjects"
read a
read b
read c
total=$(($a+$b+$c))
avg=$(($total/3))
echo "Total:$total"
echo "Average:$avg"
echo -n "Result:"
if test $avg -ge 80 -a $avg -le 90
then
   echo "Distinction"
elif test $avg -ge 60 -a $avg -lt 80
then
   echo "First class"
elif test $avg -ge 35 -a $avg -le 59
then
   echo "Second class"
else
   echo "Fail"
fi

OUTPUT
csc@csc-SVE1513CYNB ~ $ bash avg
enter name
martin
enter class
bsc
enter marks of 3 subjects
45
54
55
Total:154
Average:51
Result:Second class

No comments:

Post a Comment