home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / answers / ch08_2.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.6 KB  |  66 lines

  1.                            -- Chapter 8 - Programming exercise 2
  2. -- Centigrade to Farenheit temperature table
  3. --
  4. --  This program generates a list of Centigrade and Farenheit
  5. --    temperatures with a note at the freezing point of water
  6. --    and another note at the boiling point of water.
  7.  
  8. with Text_IO;
  9. use Text_IO;
  10.  
  11. procedure CH08_2 is
  12.  
  13.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  14.    use Int_IO;
  15.  
  16.    Centigrade, Farenheit : INTEGER;
  17.  
  18.    function Cent_To_Faren(Cent : INTEGER) return INTEGER is
  19.    begin
  20.       return (32 + Cent * 9 / 5);
  21.    end Cent_To_Faren;
  22.  
  23. begin
  24.    Put("Centigrade to Farenheit temperature table");
  25.    New_Line(2);
  26.    for Count in INTEGER range -2..12 loop
  27.       Centigrade := 10 * Count;
  28.       Farenheit := Cent_To_Faren(Centigrade);
  29.       Put("C =");
  30.       Put(Centigrade,5);
  31.       Put("    F =");
  32.       Put(Farenheit,5);
  33.       if Centigrade = 0 then
  34.          Put("  Freezing point of water");
  35.       end if;
  36.       if Centigrade = 100 then
  37.          Put("  Boiling point of water");
  38.       end if;
  39.       New_Line;
  40.    end loop;
  41. end CH08_2;
  42.  
  43.  
  44.  
  45.  
  46. -- Result of execution
  47.  
  48. -- Centigrade to Farenheit temperature table
  49. --
  50. -- C =  -20    F =   -4
  51. -- C =  -10    F =   14
  52. -- C =    0    F =   32  Freezing point of water
  53. -- C =   10    F =   50
  54. -- C =   20    F =   68
  55. -- C =   30    F =   86
  56. -- C =   40    F =  104
  57. -- C =   50    F =  122
  58. -- C =   60    F =  140
  59. -- C =   70    F =  158
  60. -- C =   80    F =  176
  61. -- C =   90    F =  194
  62. -- C =  100    F =  212  Boiling point of water
  63. -- C =  110    F =  230
  64. -- C =  120    F =  248
  65.  
  66.