PROGRAM Plastics (Input, Output);


CONST
  Plastic1Rate = 0.06;
  Plastic2Rate = 0.04;
  RatePerHour = 45;


VAR
  Truckload, Type1Weight, Type2Weight : Integer;
  Hours : Real;
  ProcessingCharge, Amount1, Amount2, Total : Real;




(*******************************************************************)
FUNCTION GetTime  : Real;

Var
  Start, Finish : Integer;
  TempTime,StartR, FinishR : Real;

Begin
  REPEAT
    Writeln('Enter start time in 24 hour format: ');
    Readln(Start);
    IF (Start<0) Or (Start>2400) THEN
      Writeln('Invalid time.  Must be between 0 and 2400.  Again please');
  UNTIL (Start>=0) And (Start<=2400);

  REPEAT
    Writeln('Enter end time in 24 hour format: ');
    Readln(Finish);
    IF (Finish<0) Or (Finish>2400) THEN
      Writeln('Invalid time.  Must be between 0 and 2400.  Again please');
  UNTIL (Finish>=0) And (Finish<=2400);

  StartR := (Start Div 100) + ((Start Mod 100) / 60);
  FinishR := (Finish Div 100) + ((Finish Mod 100) / 60);

  IF FinishR > StartR THEN
    TempTime := FinishR - StartR
  ELSE
    TempTime := (24 - StartR) + FinishR;
  GetTime := TempTime;
  Writeln('Time= ',TempTime:6:2);
End;





(*******************************************************************)
PROCEDURE GetWeights (Var TruckWeight, Plastic1Weight, Plastic2Weight
                      : Integer);

Begin
  REPEAT
    Writeln('Enter weight of truckload of junk: ');
    Readln(TruckWeight);
    Writeln('Enter amount of plastic of type 1 recovered: ');
    Readln(Plastic1Weight);
    Writeln('Enter amount of plastic of type 2 recovered: ');
    Readln(Plastic2Weight);
    IF Plastic1Weight + Plastic2Weight > TruckWeight THEN
     Begin
      Writeln('ERROR: entered values indicate more recovered than input.');
      Writeln('Truck load entered: ',TruckWeight:1);
      Writeln('Plastic of type 1 entered: ',plastic2Weight:1);
      Writeln('Plastic of type 2 entered: ',plastic2Weight:1);
      Writeln('Please re-enter all values.');
     End;
  UNTIL Plastic1Weight + Plastic2Weight <= TruckWeight;
End;

 



            
(*******************************************************************)
PROCEDURE Output (Truckload, Type1 : Integer;
                  Rate1, Amount1 : Real;
                  Type2 : Integer;
                  Rate2, Amount2, 
                  Charge, Total : Real);

Begin
  Writeln('Number of pounds in the truck:               ',Truckload:1);
  Writeln('Number of pound of type 1 plastic recovered: ',Type1:1);
  Writeln('@ ',Rate1:6:2,' per pound  =  ',Amount1:8:2);
  Writeln('Number of pound of type 2 plastic recovered: ',Type2:1);
  Writeln('@ ',Rate2:6:2,' per pound  =  ',Amount2:8:2);
  Writeln('Processing fee:         -',Charge:8:2);
  Writeln('Payment due :            ',Total:8:2);
End;





(*******************************************************************)
BEGIN

  ProcessingCharge := GetTime * RatePerHour;

  GetWeights(Truckload, Type1Weight, Type2Weight);

  Amount1 := Type1Weight * Plastic1Rate;
  Amount2 := Type2Weight * Plastic2Rate;

  IF ProcessingCharge > Amount1 + Amount2 THEN
    Total := 0
  ELSE
    Total := Amount1 + Amount2 - ProcessingCharge;

  Output(Truckload,Type1Weight,Plastic1Rate,Amount1,
         Type2Weight,Plastic2Rate,Amount2,
         ProcessingCharge,Total);
END.
