Comments about the Fahrenheit to Celcium program
Here is the first version of the program that we created
in class.
put "Fahrenheit Celcius"
var fahr: int
var cel: real
for i: -2..10
fahr := i * 10
cel := (fahr - 32) * 5/9
put fahr, " ", cel
end for
Here is a better version of the program which we developed in the lecture.
const fahr2cel_add : int := -32
const fahr2cel_mul : real := 5/9
put "Fahrenheit Celcius"
put "---------- -------"
for i: -2..10
var cel : real % must be real
var fahr : real % make it real for matching format
fahr := i* 10 % to give the specified intervals
cel := (fahr+fahr2cel_add)*fahr2cel_mul % the conversion
put fahr:7:1, cel:10:1 % #'s after : are for formatting
end for
Although it is not advised, you could also do it this way.
put "Fahrenheit Celcius"
put "---------- -------"
for i: -2..10
put i*10.0:7:1,(i*10-32)*0.5556:10:1
end for