LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-16-2006, 02:03 PM   #1
reddawn
LQ Newbie
 
Registered: Jul 2006
Posts: 1

Rep: Reputation: 0
Help Please - averging input in a shell script


I am writing a shell script for an assignment and I am to:
Read in three grades from the keyboard
Average the grades
Display the appropriate letter grade for the number grade using this scale:
90 to 100: Display a letter grade of A
80 to 89: Display a letter grade of B
70 to 79: Display a letter grade of C
65 to 69: Display a letter grade of D
0 to 64: Display a letter grade of F

So far I have done this which I think I dont need to declare so many - how do I make it where I can input the grades then average them? any help would be great - i am a complete

So far I have done this -

declare Grade1
read -p "Enter Grade: " Grade
if [[ $Grade1= "100 - 90" ]]
then
echo "your grade is a A"
if [[ $Grade1= "80 to 89" ]]
then
echo "your grade is a B"
if [[ $Grade1= "70 to 79" ]]
then
echo "your grade is a C"
if [[ $Grade1= "65 to 69" ]]
then
echo "your grade is a D"
if [[ $Grade1= "0 to 64" ]]
then
echo "your grade is a F"

declare Grade2
read -p "Enter Grade: " Grade
if [[ $Grade2= "100 - 90" ]]
then
echo "your grade is a A"
if [[ $Grade2= "80 to 89" ]]
then
echo "your grade is a B"
if [[ $Grade2= "70 to 79" ]]
then
echo "your grade is a C"
if [[ $Grade2= "65 to 69" ]]
then
echo "your grade is a D"
if [[ $Grade2= "0 to 64" ]]
then
echo "your grade is a F"


declare Grade3
read -p "Enter Grade: " Grade
if [[ $Grade3= "100 - 90" ]]
then
echo "your grade is a A"
if [[ $Grade3= "80 to 89" ]]
then
echo "your grade is a B"
if [[ $Grade3= "70 to 79" ]]
then
echo "your grade is a C"
if [[ $Grade3= "65 to 69" ]]
then
echo "your grade is a D"
if [[ $Grade3= "0 to 64" ]]
then
echo "your grade is a F"
 
Old 07-16-2006, 02:41 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Take a look at this bash howto:
http://www.tldp.org/HOWTO/Bash-Prog-...O-7.html#ss7.2
 
Old 07-16-2006, 02:44 PM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

Rep: Reputation: 68
Read man bash. Pay special attention to "read", "$(( ))", "[ ]"/"test", "if". It is a feasible way to complete your - did I guess? - homework. Try to do part of task afterwards, and step-by-step add functionality. Post concrete questions if you have problems.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script pipe input - bash mostly laikos Programming 4 11-09-2008 06:14 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
help on shell script as a wrapper to launch default programs according to input file daveiro Programming 2 11-24-2005 05:20 PM
how can I take input with a shell script? GUIPenguin Linux - General 4 04-11-2005 04:46 PM
Shell script user input tuckermaddox Linux - Newbie 5 08-12-2004 04:14 AM


All times are GMT -5. The time now is 12:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration