3/22/11

pricelist program in pascal syntax (array, while do, for to do, if then else)

Pricelist is table may contains data of items name and price. From this pricelist you may get data about average of the price, the cheapest and the most expensive items price. The user can search the specific item price with only type the item name.
This is the syntax:

uses wincrt;
type data1=array [1..20] of string;
type data2=array [1..20] of real;
var
position,n,i:byte;
name:data1;
price:data2;
found:boolean;
find1:string;
again:char;
find2,average,min,max,total:real;
begin
  repeat;
  begin
    inc(n);
    writeln('Input the items name',n,'for stop type xxx==>');
    readln(name[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        Price');
    writeln('--------------------------------');
    for i:=1 to n do
      writeln(i:3,'|',name[i]:13,'| $',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 min:=price[i];find1:=name[i];
end;
writeln('The cheapest item is ',find1,' with price       ==> $ ',min:10:2);

for i:=2 to n do
begin
if max<price[i] then max:=price[i];find1:=name[i];
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);
  found:=false;
  for i:=1 to n do
  begin
   if name[i]=find1 then found:=true;position:=i;find2:=price[i];
  end;
   writeln;
   if found then writeln('The price of ',find1,' is $ ',find2:10:2,' as data number ',position)
   else writeln('sorry there is not ',find1,' in the array');
   writeln;
   write('Do you want to do it again?<y,n>');readln(again);
end;

end.






1 comment: