You are not logged in.

#1 31 May 2012 07:48

Ernie Crawford
Member
From: Spokane
Registered: 31 May 2012
Posts: 2

Looking for help on this script.

Write a shell script to accomplish the following tasks:

Prompt the user to enter a group of test scores.

Calculate the lowest and highest scores as well as the overall average.
Print out (to the screen) the three items above and the total number of scores supplied by the user.
Ask the user if (s)he has any more to process. If so, perform the above operations for the new batch of scores. If not, exit the script.

Offline

#2 05 Jun 2012 06:39

Ernie Crawford
Member
From: Spokane
Registered: 31 May 2012
Posts: 2

Re: Looking for help on this script.

Here is what I have so far. It works unless I enter a score of 100 then it  makes 100 as the low number what am I doing wrong?

#!/bin/bash

((low=999999))




echo "Test Score Average Calculator"

echo -n "How many student scores do you have to enter: "
read qty

until [[ $amt = $qty ]]
do
       ((amt = amt + 1))
       echo -n "Enter student scores please $amt: "
       read scr

       if [[ $scr > $high ]]
       then
         ((high = scr))
       fi

       if [[ $scr < $low ]]
       then
          ((low = scr))
       fi

       ((avg = avg + scr))

done

       ((finavg = avg / qty))
echo "You entered $amt scores."
echo "Average score is $finavg."
echo "Highest score is $high."
echo "Lowest score is $low."
echo
    if [[ $finavg < 50 ]]
    then
    echo "Your Studends Need Help"
    fi
   
    if [[ $finavg > 90 ]]
    then
      echo "Your Students have done very well"
    fi
echo
echo "If you would like to enter another group of"
echo -n "scores then please enter how many (0 exits) "
echo -n "How many student scores do you have to enter: "

read quant

if  [[ $quant = 0 ]]
then
exit
fi

               until [[ $num = $quant ]]
               do
                       ((num = num + 1))
                       ((min=999999))
                       echo -n "Enter score for test number $num: "
               read scr
               if [[ $scr > $max ]]
               then
                 ((max = scr))
               fi

               if [[ $scr < $min ]]
               then
                  ((min = scr))
               fi

               ((aver = aver + scr))
               ((finaver = aver / quant))
               done


echo "You entered $num scores."
echo "Average score is $finaver."
echo "Highest score is $max."
echo "Lowest score is $min."

echo
    if [[ $finavg < 50 ]]
    then
    echo "Your Studends Need Help"
    fi
   
    if [[ $finavg > 90 ]]
    then
      echo "Your Students have done very well"
    fi

Offline

Board footer

Powered by