Skip to main content

Algorithm/Coding Layout

Problem: CarHireSystem Program CarHireSystem;

Data Table

Identifier
StartMiles, StopMiles, TotalMiles - Integer
StandardCharge, Surcharge, TotalCharge - Real

 
{ Data Section }
Var
StartMiles, StopMiles, TotalMiles : Integer;
StandardCharge, Surcharge, TotalCharge: Real;
 

Algorithm

Begin

Display 'Enter miles at start of hire: '
Get StartMiles

Loop while StartMiles is not equal to 0
{ BeginLoop }

Display 'Enter miles at end of hire: '
Get StopMiles

Calc TotalMiles as StopMiles - StartMiles
Calc StandardCharge as TotalMiles * 0.20
Calc Surcharge as (TotalMiles DIV 1000) * 25
Calc TotalCharge as StandardCharge + Surcharge

Display 'Total cost of hire ' , TotalCharge

Disp 'Enter miles at start of hire (0 to exit): '
Get StartMiles

EndLoop { While }

End

 
{ Main Program }

Begin { CarHireSystem }

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

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

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

TotalMiles := StopMiles - StartMiles
StandardCharge := TotalMiles * 0.20
Surcharge := (TotalMiles DIV 1000) * 25
TotalCharge := StandardCharge + Surcharge

Writeln ('The total cost of the hire is ' , TotalCharge:8:2);

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

End; { Loop }

End. { CarHireSystem }
 


Next: Example Program Code