Skip to main content

Example Program Code

The final program could be as follows:

 
Program CarHireSystem;

Var
StartMiles : Integer;
StopMiles  : Integer;
TotalMiles : Integer;

StandardCharge : Real;
Surcharge : Real;
TotalCharge : Real;

Begin { CarHireSystem }

Writeln ('Enter miles at start of hire: ');
Readln (StartMiles);

While (StartMiles <> 0) Do
Begin { While }

Writeln ('Enter miles at end of hire: ');
Readln (StopMiles);

TotalMiles := StopMiles  StartMiles;

StandardCharge := TotalMiles * 0.20;

Surcharge := (TotalMiles DIV 1000) * 25;

TotalCharge := StandardCharge + Surcharge;

Writeln ('The total cost of hire ', TotalCharge:4:2);

Writeln ('Enter miles at start of hire (0 to exit): ');
Readln (StartMiles);

End; { While }

End. { CarHireSystem }
 

Next: Loop Overview