This is the syntax.
uses wincrt;
type data1=array [1..20] of string;
type data2=array [1..20] of real;
var
position,n,i,x:byte;
name,color:data1;
price:data2;
found:boolean;
find1,find2:string;
again:char;
find3,average,min,max,total:real;
begin
repeat;
begin
inc(n);
writeln('Input the items name ',n:2,' for stop type xxx==>');
readln(name[n]);
writeln('Input the items color ==>');
readln(color[n]);
writeln('Input the items price ==>');
readln(price[n]);
total:=total+price[n];
end
until(name[n]='xxx');
dec(n);
clrscr;
writeln('PRICE LIST BLANTIK ONLINE');
writeln('No Name Color Price');
writeln('--------------------------------------');
for i:=1 to n do
writeln(i:3,'|',name[i]:13,'|',color[i]:10,' $',price[i]:10:2);
writeln('--------------------------------------');
{Min, max, average}
average:=total/n;
min:=price[1];
max:=price[1];
find1:=name[1];
writeln('The average of the items price is ==> $ ',average:10:2);
for i:=2 to n do
begin
if min>price[i] then begin min:=price[i];find1:=name[i];end;
end;
writeln('The cheapest item is ',find1,' with price ==> $ ',min:10:2);
for i:=2 to n do
begin
if max<price[i] then begin max:=price[i];find1:=name[i];end;
end;
writeln('The most expensive item is ',find1,' with price ==> $ ',max:10:2);
{searching}
again:='y';
while again='y'do
begin
writeln;
write('Which items price are you lokking for? ');readln(find1);
write('Which color do You want? ');readln(find2);
found:=false;
for i:=1 to n do
begin
if name[i]=find1 then
begin
if color[i]=find2 then
begin
found:=true;position:=i;find3:=price[i];
end;
begin
found:=true;position:=i;find3:=price[i];
end;
end;
end;
writeln;
if found then writeln('The price of the ',find2,' ',find1,' is $ ',find3:10:2,' as data number ',position,'.')
else writeln('sorry there is not ',find2,' ',find1,' in the array.');
writeln;
write('Do you want to do it again?<y,n> ');readln(again);
end;
end.
No comments:
Post a Comment