»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 04-20-2004, 01:55 AM   #1 (permalink)
Registered User
 
[Neo770]'s Avatar
 
Join Date: Oct 2001
Location: Gold Coast,Australia
Posts: 1,188
[Neo770] is on a distinguished road
Bash scripting help

Hi all,

We got this mini test like 2 weeks ago and I have no clue how to do it.

Here what we wew asked to do:

Program will prompt user for correct information, then calculate charge from the following table.

Code:
Weight	        Destination	Handling Code	Surcharge
10-  100	Brisbane          S	                  10
101-200	       Brisbane          S	                 15
10-  100	Brisbane          E	                  20
101-200	       Brisbane          E	                 35
10-  100	Sydney	          S	                  12
101-200	       Sydney	         S	                 19
10-  100	Sydney	          E	                  28
101-200	       Sydney	         E	                 45
The program will tell the user the following information in this format:

Package of 10 grams
Destination Sydney
Surcharge 12.00
Handling S

-----

Im not a complete newbi at scripting, im just hopeless at figuring out these kinds of problems, so a point in the direction of where I should start would be great. This is not a test for grading so dont worry about helping to much..

Thanks.


Last edited by [Neo770]; 04-21-2004 at 03:26 AM.
[Neo770] is offline   Reply With Quote
Old 04-20-2004, 09:52 AM   #2 (permalink)
Registered User
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 2,567
krohnjw is on a distinguished road
Send a message via AIM to krohnjw
Well, basically just use echo to send out information, read to get info.
That info will come in as the $REPLY variable, so that you can set up conditionals to calculate your charge.

eg.
#!/bin/bash

echo "Enter some random number sucka"
read
echo "Here it is again"
echo $REPLY
krohnjw is offline   Reply With Quote
Old 04-20-2004, 04:14 PM   #3 (permalink)
Registered User
 
[Neo770]'s Avatar
 
Join Date: Oct 2001
Location: Gold Coast,Australia
Posts: 1,188
[Neo770] is on a distinguished road
Thanks, but the bit that I need help with is the process of calculating the charge.
[Neo770] is offline   Reply With Quote
Old 04-20-2004, 10:09 PM   #4 (permalink)
Registered User
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 2,567
krohnjw is on a distinguished road
Send a message via AIM to krohnjw
Ah, sorry
Well, the easiest way to do it is to construct nested conditionals.
I dont know how you will prompt for the information, but an easy way to do it would be as so
Code:
if (type)
     if (dest)
         if (length)
else //other type
     if (dest)
        if (length)
with the appropriate elseif statements.

I don't know if I understand where your problem lies here Feel free to be more specific, ie the logic, actual calculation, etc and this could be made much simpler
krohnjw is offline   Reply With Quote
Old 04-21-2004, 03:29 AM   #5 (permalink)
Registered User
 
[Neo770]'s Avatar
 
Join Date: Oct 2001
Location: Gold Coast,Australia
Posts: 1,188
[Neo770] is on a distinguished road
Ok the logic is where I always have trouble in programming. This is a network engineering course not a programming course.

The teacher started to work through the solution in class today.

It went something like:

if weight is greater then 10 and less then 100 then process low weight

else process high weight if between 100 and 200

---------
That’s how the if statement started out

Basically say that the weight was 50 going to brisbane with Standard handling then the program would say it equals 10

He said it could also be done with the case statement but as to not confuse us he is only showing us the if/then way.

That’s as far as we got today and next Linux scripting class is not till next week unfortunately.

Thanks for the help so far
[Neo770] is offline   Reply With Quote
Old 04-21-2004, 09:12 PM   #6 (permalink)
Registered User
 
Mike's Avatar
 
Join Date: Oct 2001
Location: In a Cali Valley
Posts: 7,817
Mike is on a distinguished road
Send a message via AIM to Mike
Quote:
Originally posted by krohnjw
echo "Enter some random number sucka"
Yes, the best line of code ever...

Where was Eddy on this one? I know he loves bash scripting...
Mike is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 04:45 PM.