Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!uwm.edu!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!uxc.cso.uiuc.edu!s.cs.uiuc.edu!mccaugh From: mccaugh@s.cs.uiuc.edu Newsgroups: comp.lang.pascal Subject: Re: Fahrenheit Celsius HELP!! Message-ID: <208300017@s.cs.uiuc.edu> Date: 6 Oct 89 09:40:48 GMT References: <16843@watdragon.waterloo.edu> Lines: 48 Nf-ID: #R:watdragon.waterloo.edu:16843:s.cs.uiuc.edu:208300017:000:1527 Nf-From: s.cs.uiuc.edu!mccaugh Oct 4 03:11:00 1989 > I need a simple piece of code to convert a string celsius/fahrenheit > to a fahrenheit/celsius. The input is of the form [digit][F|C] ie 32C, 0F > For some reason... the code below does not work! I need this by Monday morning > Can anyone out in netland help me out? :-) > ----------------------------------------------(code follows....) Shawn: > if ( input@ = 'F' ) then > begin > writeln( 'fahrenheit '); > convert := value; > end > else > begin > writeln( 'celsius '); > convert := value; > end; > end; > > begin > writeln( convert ); > end. > Your code correctly converts a string to an integer number, but that's all. In 1948, the Ninth General Conferenace on Weights & Measures decided to ex- change the name 'Centigrade' for 'Celsius' after the Swede who invented the scale in 1742. Since Fahrenheit ranges from 32 to 212 (= 180 pts) compared to 100 pts for Celsius (hence the original name 'Centigrade'), there exist 180/100 = 9/5 as many F values as C values, leaving each F interval 5/9 of a C interval. This, together with the necessity to correct for 0 yields: C = 5/9*(F - 32) Thus if you are given a value V known to be Fahrenheit and wish to convert it to Celsius: convert = 0.555555555*(V - 32.0). Solving for F: F = 9/5*C + 32 so if value V is know to be Celsius, convert = 1.8*C + 32.0. Hope this has helped! Scott McCaughrin University of Illinois Urbana, Illinois (mccaugh@s.cs.uiuc.edu)