program SteelCost; { program computing cost of steel needed for counted lots of ballbearings and roller bearing lots with flag-controlled loop. R. Rosebrugh October 5, 1993} const Price = 0.52; {price per cc of steel - the units used below} var More, BType : Char; {input - loop control and bearing type} Radius, Length : Real; {input - radii in cm } LotSize, Lotcount : Integer; {input - numbers required} Counter : Integer; Flag: Boolean; {loop control} Volume, Cost : Real; {output - volumes and cost} procedure Ball; {process ball-bearing lots} begin WriteLn ('Type the radius (decimal number) in centimetres'); WriteLn ('lot size (whole number) and lot count for ball bearings'); ReadLn (Radius,Lotsize,Lotcount); Counter := 1; Volume := 0.; while Counter < LotCount do begin Volume := 4/3*Pi*Sqr(Radius)*Radius*Lotsize + Volume; Counter := Counter + 1 end{While Counter} end{Ball}; procedure Roller; {process roller-bearing lots} begin WriteLn ('Type the radius and length (decimal numbers) in centimetres'); WriteLn ('and lot size (whole number) for roller bearings'); ReadLn (Radius,Length,Lotsize); Volume := Pi*Sqr(Radius)*Length*Lotsize; end{Roller}; begin{main program} Cost := 0.; {initialize accumulating variable} Flag := False; {initialize flag to false} while not(Flag) do begin WriteLn ('What type of lot? Type ''B'' for ball, ''R'' for roller'); Readln (BType); if Btype='B'then Ball else if Btype='R' then Roller else WriteLn ('Input error, ignore program output'); Cost := Volume * Price + Cost; Writeln ('Another lot?'); ReadLn (More); if More<>'Y' then {or equivalently Flag := (More <> 'Y') } Flag := True end;{while More} WriteLn ('The total cost is $', Cost:5:2); end.