我希望我可以通过我的脚本获得一些帮助。它是一个gpa计算器,它会输出平均成绩点,然后输入99。 这就是我到目前为止所拥有的
#! /bin/bash
sum=0
count=1
read -p "Enter A Grade Point: " grade
while (( $(echo "$grade != 99" | bc) )); do
count=$(( count + 1 ))
sum=$(echo "scale=2;($sum+$grade)" | bc)
read -p "Enter A Grade Point: " grade
if [[ "$grade" == 99 ]]; then
break
fi
exit 1
done
avg=$(echo "scale=2;($sum/$count)" | bc)
if (( avg < 4 )); then
echo "Your GPA is $avg"
echo "This is an B!"
elif
(( avg < 3 )); then
echo "Your GPA is $avg"
echo "This is a C!"
elif
(( avg < 2 )); then
echo "Your GPA is $avg"
echo "This is a D!"
elif
(( avg < 1 )); then
echo "Your GPA is $avg"
echo "This is a F!"
else
echo "Your GPA is $avg"
echo "This is a A!"
fi
exit 0
答案 0 :(得分:0)
我没有bc命令检查此代码,但请尝试此操作。
leaseTasks()
答案 1 :(得分:0)
#!/bin/bash
sum=0
count=1
read -p "Enter A Grade Point: " grade
while [ $grade != 99 ]
do
count=$(( count + 1 ))
sum=$(echo "scale=2;($sum+$grade)" | bc)
read -p "Enter A Grade Point: " grade
echo "entered loop"
done
avg=$(echo "scale=2;($sum/$count)" | bc)
if [[ $avg < 4 ]]
then
echo "Your GPA is $avg"
echo "This is an B!"
elif [[ $avg < 3 ]]
then
echo "Your GPA is $avg"
echo "This is a C!"
elif [[ $avg < 2 ]]
then
echo "Your GPA is $avg"
echo "This is a D!"
elif [[ $avg < 1 ]]
then
echo "Your GPA is $avg"
echo "This is a F!"
else
echo "Your GPA is $avg"
echo "This is a A!"
fi
不确定程序的逻辑,但现在应该删除错误。请检查