Page 1 of 1

Converting from fahrenheit to celcius problem.

Posted: Wed Sep 15, 2004 1:50 pm
by GeoTrail
I'm having some problems when converting from celcius to fahrenheit.
When I input 22 celcius it gives back 71. Think that is correct.
But when I try to convert 71 fahrenheit to celcius it returns 21 instead of 22. Could anyone help me with this?

Code: Select all

Procedure.l celcius2fahrenheit(in.l)
  Result.l = (in.l * 9/5) + 32
  ProcedureReturn Result.l
EndProcedure

Procedure.l fahrenheit2celcius(in.l)
  Result.l = (in.l-32) * 5/9
  ProcedureReturn Result.l
EndProcedure

Debug celcius2fahrenheit(22)
Debug fahrenheit2celcius(71)

Posted: Wed Sep 15, 2004 1:59 pm
by freedimension
You want to code with floats? So why don't you do it :D

Code: Select all

Procedure.l celcius2fahrenheit(in.l) 
  Result.l = (in.l * 9.0/5.0) + 32 
  ProcedureReturn Result.l 
EndProcedure 

Procedure.l fahrenheit2celcius(in.l) 
  Result.l = (in.l-32) * 5.0/9.0
  ProcedureReturn Result.l 
EndProcedure 

Debug celcius2fahrenheit(22)
Debug fahrenheit2celcius(71)

Posted: Wed Sep 15, 2004 2:06 pm
by GeoTrail
Was that all? :lol:
Thanks, I didn't even think about that.

Cheers m8 :)

Posted: Wed Sep 15, 2004 2:14 pm
by PB
According to both http://www.onlineconversion.com/temperature.htm and
http://www.allmeasures.com/temperature.html we see that 22 c = 71.6 f,
and that 71.6 f = 22 c. So here's my offering that does the job:

Code: Select all

Procedure.s c2f(c.f)
  ProcedureReturn StrF((c*9/5)+32,1)
EndProcedure

Procedure.s f2c(f.f)
  ProcedureReturn StrF((f-32)*5/9,1)
EndProcedure

Debug c2f(22)
Debug f2c(71.6)
(@Freedimension: Your code is wrong -- it returns 72 instead of 71.6). ;)

Posted: Wed Sep 15, 2004 2:18 pm
by freedimension
PB wrote: (@Freedimension: Your code is wrong -- it returns 72 instead of 71.6). ;)
Darn, i knew i missed something :D

Posted: Wed Sep 15, 2004 2:36 pm
by GeoTrail
Great, thanks alot PB.
The more accurate the better ;)