Q. Try out the program below and comment on the output using TPW.

program sales_eg;

{program to accumulate sales totals for three salesmen}

uses crt; {calls in Turbo Pascal's library routines}

var

   grand_total, total1, total2, total3, amount: real;

   salesman : integer;

procedure intialise;

begin

    clrscr; {clear screen}

    grand_total := 0;

    total1 := 0;

    total2 := 0;

    total3 := 0;

end; {procedure}

procedure process_data;

begin

   write('Please enter salesperson's number (0 to finish): ');

   readln(salesman);

   while salesman<> 0 do

      begin

        write('Enter sales amount: ');

        readln(amount);

       if (salesman=1) then total1 := total1 + amount;

       if (salesman=2) then total2 := total2 + amount;

       if (salesman=3) then total3 := total3 + amount;

       grand_total := grand_total + amount;

       write('Please enter next salesperson's number (0 to finish): ');

       readln(salesman)

     end;

{endwhile}

end; {procedure}

procedure output_totals;

begin

    writeln;

    writeln('Total for salesperson 1: ',total1:8:2);

    writeln('Total for salesperson 2: ',total2:8:2);

    writeln('Total for salesperson 3: ',total3:8:2);

    writeln('Grand total of all sales: ',grand_total:8:2)

end; {procedure}

{************MAIN PROGRAM***********}

begin

    intialise;

    process_data;

   output_totals;

end.

SUBMISSION DEADLINE: 16/3/2006 (Thursday)

Hosted by www.Geocities.ws

1