I'm trying to get this script to include a while loop that queries the user to choose if they want to run it again or not. I'm not sure what the while loop construct should be or where in the script to put it.
Here's the meat of the program:
Code:
#!/bin/bash
# Bash shell script to calculate student average
# Usage: ./grade1.sh
# Declare some integer type variables
echo -n "Do you wish to enter another set of scores? (y/n) "
read CHOICE
while [ "$CHOICE" != "n" ]
do
declare -i test1
declare -i test2
declare -i test3
declare -i test4
declare -i lab
declare -i sum
echo
echo "=================="
echo "Grade Calculator "
echo "=================="
echo
read -p "Enter first name: " firstname
read -p "Enter last name: " lastname
echo
read -p "Enter test score 1: " test1
read -p "Enter test score 2: " test2
read -p "Enter test score 3: " test3
read -p "Enter test score 4: " test4
read -p "Enter lab score: " lab
sum=$test1+$test2+$test3+$test4+$lab
average=$((sum/5))
if [ $average -ge 90 ]; then
grade="A";
elif [ $average -ge 80 ]; then
grade="B";
elif [ $average -ge 70 ]; then
grade="C";
elif [ $average -ge 60 ]; then
grade="D"
elif [ $average -le 60 ]; then
grade="F"
fi
echo "Course Grade: "$grade
echo
echo "Grade results . . ."
echo "Student name: $firstname $lastname"
echo "Total points: $sum"
echo "Course average: $average"
echo
case $grade in
A) echo "An 'A' represents superior course work."
;;
B) echo "A 'B' represents above average course work."
;;
C) echo "A 'C' represents average course work."
;;
D) echo "A 'D' represents below average course work."
;;
F) echo "An 'F' represents failing course work."
;;
esac
done