Example Program: THERMO

Top  Previous  Next

The following program uses real numbers to convert degrees Fahrenheit to degrees Celsius.

 

        \THERMO.XPL     01-AUG-2005

        \This program prints a table of Fahrenheit temperatures

        \ and their Celsius equivalents.

 

        code    CrLf=9, Text=12;

        code real RlOut=48, Format=52;

        real    Fahr,   \Fahrenheit temperature

                Cel;    \Celsius temperature

 

        begin

        \Print table heading:

        Text(0, "FAHRENHEIT     CELSIUS");

        CrLf(0);

 

        Format(3, 1);           \Define real-number format

 

        Fahr:= -40.0;

        while Fahr <= 100.0 do

                begin

                Cel:= 5.0/9.0 * (Fahr - 32.0);  \Calculate Celsius

                RlOut(0, Fahr);                 \Print out results

                Text(0, "               ");     \(2 tabs)

                RlOut(0, Cel);

                CrLf(0);

                Fahr:= Fahr + 20.0;             \Next step

                end;

        end;

 

When THERMO executes, it displays the following:

 

        FAHRENHEIT      CELSIUS

        -40.0           -40.0

        -20.0           -28.9

          0.0           -17.8

         20.0            -6.7

         40.0             4.4

         60.0            15.6

         80.0            26.7

        100.0            37.8

 

CrLf and Text are intrinsics we have used before, but RlOut and Format are new. RlOut (ReaL OUT) outputs real numbers in a format specified by Format. Here we are specifying a format of three places (including the minus sign) before the decimal point and one place after it.