home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol080 / checkln.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-02-10  |  3.1 KB  |  96 lines

  1. {    This was part of a Pascal Course (this is program 
  2. Listing 5 of Welsh & Elder, page 101). It has been modified 
  3. only very slightly to provide a better input/output format.
  4. Donated by Gerald Hewett }
  5.  
  6.  
  7. Program Checkln;
  8.  
  9.      type range =0..999;
  10.  
  11.      var  dollars : range;
  12.             cents : 0..99;
  13.  
  14.      Procedure convertintowords (x : range);
  15.  
  16.           type digit = 0..9;
  17.           var  h,t,u : digit;
  18.  
  19.           Procedure units (i : digit);
  20.                Begin
  21.                     case i of
  22.                          0 : ;
  23.                          1 : write ('One ');
  24.                          2 : write ('Two ');
  25.                          3 : write ('Three ');
  26.                          4 : write ('Four ');
  27.                          5 : write ('Five ');
  28.                          6 : write ('Six ');
  29.                          7 : write ('Seven ');
  30.                          8 : write ('Eight ');
  31.                          9 : write ('Nine ');
  32.                     end
  33.                end;      (*Units*)
  34.  
  35.           Begin
  36.                h := x div 100;
  37.                t := x mod 100 div 10;
  38.                u := x mod 10;
  39.                if h >0 then 
  40.                     begin 
  41.                          units (h);
  42.                          write('Hundred ');
  43.                     end;
  44.                if t = 1 then case u of 
  45.                     0 : write('Ten ');
  46.                     1 : write('Eleven ');
  47.                     2 : write('Twelve ');
  48.                     3 : write('Thirteen ');
  49.                     4 : write('Fourteen ');
  50.                     5 : write('Fifteen ');
  51.                     6 : write('Sixteen ');
  52.                     7 : write('Seventeen ');
  53.                     8 : write('Eighteen ');
  54.                     9 : write('Nineteen ');
  55.               end   Ã¨          
  56.  
  57.  
  58.              else begin
  59.                 case t of
  60.                     0 : ;
  61.                     2 : write('Twenty ');
  62.                     3 : write('Thirty ');
  63.                     4 : write('Forty ');
  64.                     5 : write('Fifty ');
  65.                     6 : write('Sixty ');
  66.                     7 : write('Seventy ');
  67.                     8 : write('Eighty ');
  68.                     9 : write('Ninety ');
  69.                end;
  70.                units(u)
  71.           end  
  72.      end;     (*Converttowords*)
  73.  
  74.      Begin
  75.           writeln;
  76.           writeln('Enter the amount to be printed.');
  77.           writeln('Use a space, not a period!');
  78.           read(dollars);
  79.           while dollars >= 0 do
  80.                begin
  81.                read(cents);
  82.                write(dollars : 4, cents : 3, ' ' : 5);
  83.                if (dollars=0) and (cents=0) then
  84.                     write('Nil')
  85.                else begin
  86.                     if dollars > 0 then
  87.                          begin
  88.                               convertintowords (dollars);
  89.                write('Dollar≤ and ',cents : 2,' cents.')
  90.                               end;
  91.                          end;
  92.                writeln;
  93.                read(dollars)
  94.           end
  95.      end.
  96.