program metric_to_imperial;
(* This program takes any given weight (in grams) and converts it
into the relevent number of tons, stones, pounds and ounces *)
const GRAM_TO_OUNCE = 0.035;
type IMPERIAL = (ton, stone, pound, ounce);
var Ounces, Number: ARRAY[ton..ounce] of INTEGER;
Metric_Weight: REAL;
Imperial_Weight: INTEGER;
Unit: IMPERIAL;
procedure Initialise_Array;
begin
Ounces[ton]:=2000;
Ounces[stone]:=16*14;
Ounces[pound]:=16;
Ounces[ounce]:=1;
end;
procedure List_Units;
begin
WriteLn ('tons: ',Number[ton]);
WriteLn ('stones: ',Number[stone]);
WriteLn ('pounds: ',Number[pound]);
WriteLn ('ounces: ',Number[ounce]);
end;
begin (* main *)
Initialise_Array;
ClrScr; Write ('Enter weight (in grams): '); ReadLn (Metric_Weight);
Imperial_Weight:=Round(Metric_Weight*GRAM_TO_OUNCE);
for Unit:=ton to ounce do
begin
Number[Unit]:=Imperial_Weight DIV Ounces[Unit];
Imperial_Weight:=Imperial_Weight MOD Ounces[Unit];
end;
List_Units;
end. (* main *)