Hi I am trying to write a script that converts centigrade to fahrenheit and vice versa I need to use a sub-function to perform the calculations. Can anyone help me get started on this I am kinda lost and will like help learning this thank you

Recommended Answers

All 5 Replies

OH YEa also I have afile named cen which has the tempertures as follow
1
8
22
43
89
283
120
212
1043
100
287
now i need to convert these to fahrenheit

Hey There,

To convert Celsius to Fahrenheit, multiply by 1.8 and add 32 degrees.

Hope that helps you get where you're going.

nope dpesnt help me , have no clue how to sub function

Hey There,

If you're using bash, you can just do this (pseudocode to follow)

function MYFUNCTION {
code in here
return $answer
}

and then call it from the script with

MYFUNCTION arg1 arg2, etc

Inside the function, the arg's that you pass on the command line (arg1, arg2, etc) would be $1, $2, etc.

, Mike

I have the same damn homework, this is easy.

The subfunction is the datafile or the numbers you have to convert.

Place it in some type of while, for, or until loop. I found that the for loop is easiest way to go.

now to calculate the numbers you must place all of this in a $variable

Like : $c and $f

And use either let, expr, or bc to do the math for ya.

Here's a big hint. From the commandline type:

for i in `cat name of data file or temp file`
do
         echo $i

done

now calculate $i (or what ever $varible you used) with the formula for centigrade and fahrenheit .

Easy!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.