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
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`
         echo $i


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


Be a part of the DaniWeb community

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