program WaterBill;
uses winCrt;
type
customer=record
acct_no:longint;
code:char;
liter:longint;
amount:real;
end;
var
arrayC:array[1..50] of customer;
index:integer;
loop:boolean;
continue:char;
arr:customer;
PROCEDURE read_data(var data:customer);
begin
writeln('Customer Info: ');
writeln('Account number: ');
readln(data.acct_no);
writeln('Code(H,C,I) : ');
readln(data.code);
writeln('Unit of liter: ');
readln(data.liter);
end;
function calc_bill(code:char):real;
begin
if (code='H') then
begin
if (arr.liter<=15000) then
calc_bill:=0.40*(arr.liter div 1000)
else if(arr.liter>=15001) AND (arr.liter<=40000) then
calc_bill:=(0.40*(15000/1000))+(0.70*(arr.liter div 1000))
else if(arr.liter>=40001) then
calc_bill:=(0.40*(15000/1000))+(0.70*(40000/1000))+(1.10*(arr.liter div 1000));
end
else if (code='C') then
calc_bill:=1.10*(arr.liter div 1000)
else if (code='I') then
calc_bill:=1.30*(arr.liter div 1000);
end;
PROCEDURE print_bill(var print:customer);
begin
writeln('*** A&B Water Company ***');
writeln();
writeln('Account No: ',print.acct_no);
writeln('Code(H,C,I): ',print.code);
writeln('Unit of Liter: ',print.liter);
writeln('Amount Due (RM): ',arr.amount:5:2);
end;
begin
for index:=1 to 50 do
begin
read_data(arrayC[index]);
arr.amount:=calc_bill(arrayC[index].code);
print_bill(arrayC[index]);
writeln('Do you wish to continue?(Y/N):');
readln(continue);
end;
end.
It doesn't return the amount due.