program SteelCost; { program computing cost of steel needed for several lots of ballbearings and one of roller bearings. R. Rosebrugh September 30, 1993} const Price = 0.52; {price per cc of steel - the units used below} var More,BType : Char; {input - loop control and bearing type} BBRadius, RBRadius, RBLength : Real; {input - radii in cm } BBLotsize, RBLotSize : Integer; {input - numbers required} BBVolume, RBVolume, Cost : Real; {output - volumes and cost} procedure ReadNumbersSizes; {get input values for lots and dimensions} begin if BType = 'B' then begin WriteLn ('Type the radius (decimal number) in centimetres'); WriteLn ('and lot size (whole number) for ball bearings'); ReadLn (BBRadius,BBLotsize); WriteLn end{if} else begin WriteLn ('Type the radius and length (decimal numbers) in centimetres'); WriteLn ('and lot size (whole number) for roller bearings'); ReadLn (RBRadius,RBLength,RBLotsize); WriteLn end{else}; end{ReadNumbersSizes}; procedure Steelvolume; {compute volume of ball bearings and roller bearings} begin if BType = 'B' then BBVolume := 4/3*Pi*BBRadius*BBRadius*BBRadius*BBLotsize else RBVolume := Pi*RBRadius*RBRadius*RBLength*RBLotsize; end{Steelvolume}; begin{main program} Cost := 0.; {initialize accumulating variable} WriteLn ('Do you want to compute some costs? Type ''Y'' if so.'); ReadLn (More); WriteLn; while More = 'Y' do begin WriteLn ('What type of lot? Type ''B'' for ball, ''R'' for roller'); Readln (BType); ReadNumbersSizes; Steelvolume; {compute new cost, depending on type} if BType = 'B' then Cost := BBVolume * Price + Cost else Cost := RBVolume * Price + Cost; Writeln ('Another lot?'); ReadLn (More); WriteLn; end;{while More} WriteLn ('The total cost is $', Cost:5:2); {Hold output on screen:} WriteLn; WriteLn('Press return to continue'); ReadLn; end.