I want to create a linux script that will allow user to enter how many subject he/she has. The script should computer average per subject. All of the subjects has 3 terms. Prelim. Midterm and final.Script should also get the average of prelim. midterm and finals and the overall average(Prelim+Midterm+final/3)
#!/bin/bash
counter=0
number=0
declare -a my_array
read -p "Enter the number of subects:" subj
declare -a array_term=(Prelim Midterm Final)
tres=3
for(( i = 1;i <= $subj; i++ ))
do
k=0
sum=0
number=0
declare -a my_array
read -p "Enter the number of subects:" subj
declare -a array_term=(Prelim Midterm Final)
tres=3
for(( f = 1; f <= 3; f++ ))
do
read -p "Enter ${array_term[$k]} Grade for ${my_array[$k]}:" grade
grade_array+=( $grade )
prelim=$(echo "${grade_array[0]}")
midterm=$(echo "${grade_array[1]}")
final=$(echo "${grade_array[2]}")
k=$(echo $k + 1)
done
sum=$(echo $prelim + $midterm + $final | bc)
printf '%.4f\n' $(echo $sum / $tres | bc -l)
echo "Prelim Grade is:" $prelim
echo "Midterm Grade is:" $midterm
echo "Final grade is:" $final
echo "Subject Average is":
printf '%.4f\n' $(echo $sum / $tres | bc -l)
done
Result should be like this
Enter number of subject: 3
Enter subject Name: Math
Enter Prelim Grade For Math: 89
Enter Midterm Grade For Math:89
Enter Final Grade For Math:89
Math Average is: 89
Enter subject Name: English
Enter Prelim Grade For English: 90
Enter Midterm Grade For English:90
Enter Final Grade For English:90
English Average is: 90
Enter subject Name: Science
Enter Prelim Grade For Science: 91
Enter Midterm Grade For Science:91
Enter Final Grade For Science:91
Science Average is: 91
Prelim Average is: 90
Midterm Average is:90
Final Average is:90
Overall Average is:90