shell scripting project for school

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions shell scripting project for school
# 1  
Old 11-15-2011
shell scripting project for school

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

i need to prompt the user for


a) group of scores
b) calculate the lowest and highest scores and overall average
c) print out to the screen
d ask if user has any more data to process, if so repeat (loop) for a new set of scores if not exit.






2. Relevant commands, code, scripts, algorithms:



3. The attempts at a solution (include all code and scripts):
i have this much,and trust me i know there is a lot missing
Code:
#!/bin/bash
# Richard Ferguson Unix/Linux CS121

user=0
score=0
count=0

until [[$user=="done"]]

echo -n "Enter Score : "
read score

lowest=score
highest=score
howmany=1
sum=score

until[[$score==999]]
do
echo -n "Enter Score : "
sum + = $score

    if (( $score > highest ))
    then
    highest = score

        if (( $score < lowest ))
        then
        lowest = score
            if (( $score -ne 999 ))
            then
            $howmany+ = 1
            $sum+ = score
            fi
        fi
    fi
avg = $sum/$howmany
echo -n "$avg"
echo -n "$sum"
echo -n "$highest"
echo -n "$lowest"
echo
echo -n "Goodbye"    
exit 0

p.s.
when i run the file at this stage i get a e.o.f err msg that states the err is in line 45 but there is only 43 lines of code!


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
spokane falls community college
spokane wa
rick udlock
cs 121


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by zaxxon; 11-15-2011 at 11:18 AM.. Reason: code tags
# 2  
Old 11-15-2011
Thank you for filling out the template. You wouldn't believe how many try to sneak by it.

You've made a solid try but there's a lot of syntax problems you need to clean up. There's also much easier ways to do some of the things you're trying. Also, your logic isn't airtight.

Code:
#!/bin/bash
# Richard Ferguson Unix/Linux CS121

user=0
score=0
count=0
sum=0
highest=0

# set 'smallest' to a real high number, so the first number you read is always smaller!
smallest=99999


# This is wrong.  You need spaces.
# Also, use = instead of ==.
# until [[$user=="done"]]

until [[ "$user" = "done" ]]
do
        # No point doing this stuff here.  Do it ALL inside your 'score' loop.
        # echo -n "Enter Score : "
        # read score

        # This is wrong.  Needs spaces.  Also, =.
        # But you might as well just do an infinite loop.
        # until[[$score==999]]
        while true
        do
                echo -n "Enter Score : "
                # you forgot the read
                read score
                # Instantly break the loop if we get >= 999.
                # && is a short-form if/then.
                # Much easier to read than if [[ "$score" -ge 999 ]] ; then break ; fi
                [[ "$score" -ge "999" ]] && break

                # Variables don't work that way.  Use $(( )) for math.
                # sum + = $score
                sum=$((sum+score))

                # Much easier ways to do this.
                # if (( $score > highest ))
                # then
                # highest = score

                # && is a short-form "if".  [[ condition ]] && thing-executed-if-statement-is-true
                # There's also an || which does [[ condition ]] || thing-executed-if-statement-is-false
                [[ "$score" -gt "$highest" ]] && highest="$score"
                [[ "$score" -lt "$lowest" ]] && lowest="$score"

                # No reason to nest three 'ifs' here.  No reason to check for 999    inside
                # them either.
                # if (( $score < lowest ))
                # then
                # lowest = score
                #    if (( $score -ne 999 ))
                #   then
                #   $howmany+ = 1
                #    $sum+ = score
                #    fi
                #fi
                #fi

        # you forgot every one of your 'done's.
        # You should have one to match the end of each while/until/for, 
        # just like fi's match if's.
        done

        echo -n "Type 'done' to finish: "
        read user
done
# again, math doesn't work this way.
# avg = $sum/$howmany
# You can embed $(())  math in the middle of things, usefully.
# You don't need -n to print more than one thing.  Just put more than one thing into echo.
echo "average $((sum/count)) sum $sum highest $highest lowest $lowest"
echo
echo "Goodbye"    
exit 0

I don't think this code will do exactly what the assignment wants. I get the feeling they want totals per-loop, not per session, but you should ask your teacher that. I leave fixing the logic to do that up to you.

Last edited by Corona688; 11-15-2011 at 11:25 AM..
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Beginner Scripting for school

Hello people, I am new to the forum and to scripting and I'm honored to be a part of the Forum :) At the moment I'm learning to do basic scripting for school. Now I got 2 assignments that I do not understand. The case scripting I have mastered a bit. But now I have an assingment to make with... (1 Reply)
Discussion started by: hulsi88
1 Replies

2. Shell Programming and Scripting

Suggestions for Shell Scripting Project

I'm taking a class right now and need ideas for a project. The scope is relatively vague: "Create a 'mash-up' program that combines system administration functions into a single application." I would say my skills working in bash are between average and slightly above average. I was originally... (2 Replies)
Discussion started by: d3mon_spawn
2 Replies

3. UNIX for Dummies Questions & Answers

shell scripting project for school

i need to prompt the user for a) group of scores b) calculate the lowest and highest scores and overall average c) print out to the screen d ask if user has any more data to process, if so repeat (loop) for a new set of scores if not exit. i have this much,and trust me i know... (1 Reply)
Discussion started by: bodhi 926
1 Replies
Login or Register to Ask a Question