Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hey guys...having some issue using vmplayer for a unix class, and i really suck at scripts...can someone help me figure this out.
#!/bin/Project 5 2
# 22 November 2008
# Created by Charles Clay
# This program adds five numbers entered on the command line together# Check to see if five numbers were entered
if [[ $# -eq 5 ]]
then# Display the numbers entered
echo "The first number is: "$1
echo "The second number is: "$2
echo "The third number is: "$3
echo "The fourth number is: "$4
echo "The fifth number is: "$5# Add the numbers together and divide by 5 to display average
((myaver=$1+$2+$3+$4+$5/5))echo "Your average is: "$myaver
if [[ $myaver -ge 0 && $myaver -le 68 =$F ]]
then
echo "Your average is a F"
fi
echo "Your average is: "$myaverif [[ $myaver -ge 68 && $myaver -le 73 ]]
then
echo "Your average is a D"
fi
echo "Your average is: "$myaverif [[ $myaver -ge 73 && $myaver -le 79 ]]
then
echo "Your average is a C"
fi
echo "Your average is: "$myaverif [[ $myaver -ge 79 && $myaver -le 91 ]]
then
echo "Your average is a B"
fi
echo "Your average is: "$myaverif [[ $myaver -ge 91 && $myaver -le 101 ]]
then
echo "Your average is an A"
fielse
echo "Please enter only five numbers"
echo "Usage: $0 value1 value2 value3 value4 value5 /5"
exit 0fi
# End script
It calculates the wrong average and says that it can not find

First, you are performing the aritmetic incorrectly; it should be:
myaver=$(( ($1+$2+$3+$4+$5)/5))
Keep in mind that the bash shell only does integer arithmetic. In our example, any result not divisible by 5 will be truncated.
If you need more accuracy, use a tool like bc or awk to do the arithmetic. Let me know if you want an example.

mista,
you should at least add some brackets to your calculation:
((myaver=($1+$2+$3+$4+$5)/5))
cheers
Wollie

![]() |
A script to download all ...
|
setting up and using wine...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |