jeudi 3 novembre 2016

bash total and average ... and more

I'm trying to get this

Enter Incidents Mon 14 Tue 5 Wed 12

Incidents

Mon 14 Tue 5 Wed 12

Total 38

Average 7.6

Mon incidents is the highest 11

Tue incidents is the lowest 2

Enter a Day that you'd like to see how many incidents occurred? Wed

12 Incidents

So far I did the total and average, Max and min.

The problem is how to output "Mon is the highest 11. I'm able to find the min and max but can't print out the day matches the value of max and min....

!/bin/bash

echo " ----Enter Incidents-----"

echo -n "Mon= " read days[0]

echo -n "Tue= " read days[1]

echo -n "Wed= " read days[2]

echo " ------Incidents--------"

total=expr ${days[0]} + ${days[1]} + ${days[2]}

echo "Toatal is= " $total

ave=expr $total \/ 3

echo "Average= " $ave

max=${days[0]}

min=${days[0]}

for i in "${days[@]}"

do

if [[ "$i" -gt "$max" ]]; then

max="$i" 

fi

if [[ "$i" -lt "$min" ]]; then

min="$i" 

fi

done

echo "Max is:" $max

echo "Min is:" $min

this is killing me lol Mon incidents is the highest 11

Tue incidents is the lowest 2

Enter a Day that you'd like to see how many incidents occurred? Wed

12 Incidents

Aucun commentaire:

Enregistrer un commentaire