need help with this please

I'm trying to write the program for this code, but I am stuck. Please help. Thanks.
Start
prepare pay.dat for reading
Initialize the department counter to 1
Do while department counter <=7
begin
Initialize department grosspay to 0
Initialize employee pay to 0
Reset pay.dat
Do while Not EOF of pay.dat
begin
Read employee name,department number, Hourly Salary, Hours worked from pay.dat
If department number=department counter then
begin
employee pay=hourly salary * hoursworked
department grosspay=department grosspay + employee pay
endif
endwhile
print department counter, department grosspay
department counter=department counter +1
endwhile
close pay.dat
stop

This is what I have so far....
var
name:string[15]
departmentcount,departmentnumber,departmentgrosspay,employeepay:integer;
hourlysalary,hoursworked:real;
file_out:text;
begin
assign(file_out,'a:assign8.txt');
rewrite(file_out);
departmentcount:=1;
while departmentcount <=7 do
begin
departmentgrosspay:=0
employeepay:=0;
reset(file_out);
while not (eof(file_out)) do
begin
readln(file_out,name,departmentnumber,hourlysalary,hoursworked);
IF departmentnumber=departmentcount then
begin
employeepay:=hourlysalary * hoursworked
departmentgrosspay:=departmentgrosspay +employeepay
endif
endwhile
writeln(departmentcount,departmentgrosspay);
departmentcount:=departmentcount +1;
endwhile
close(file_out);
end.

Comments

  • : I'm trying to write the program for this code, but I am stuck. Please help. Thanks.
    : Start
    : prepare pay.dat for reading
    : Initialize the department counter to 1
    : Do while department counter <=7
    : begin
    : Initialize department grosspay to 0
    : Initialize employee pay to 0
    : Reset pay.dat
    : Do while Not EOF of pay.dat
    : begin
    : Read employee name,department number, Hourly Salary, Hours worked from pay.dat
    : If department number=department counter then
    : begin
    : employee pay=hourly salary * hoursworked
    : department grosspay=department grosspay + employee pay
    : endif
    : endwhile
    : print department counter, department grosspay
    : department counter=department counter +1
    : endwhile
    : close pay.dat
    : stop
    :
    : This is what I have so far....
    : var
    : name:string[15]
    : departmentcount,departmentnumber,departmentgrosspay,employeepay:integer;
    : hourlysalary,hoursworked:real;
    : file_out:text;
    : begin
    : assign(file_out,'a:assign8.txt');
    : rewrite(file_out);
    : departmentcount:=1;
    : while departmentcount <=7 do
    : begin
    : departmentgrosspay:=0
    : employeepay:=0;
    : reset(file_out);
    : while not (eof(file_out)) do
    : begin
    : readln(file_out,name,departmentnumber,hourlysalary,hoursworked);
    : IF departmentnumber=departmentcount then
    : begin
    : employeepay:=hourlysalary * hoursworked
    : departmentgrosspay:=departmentgrosspay +employeepay
    : endif
    : endwhile
    : writeln(departmentcount,departmentgrosspay);
    : departmentcount:=departmentcount +1;
    : endwhile
    : close(file_out);
    : end.
    :
    Rewrite() is used to create files. You need to change that line into Reset() and then the Reset() in your code is not necessary.
  • : Rewrite() is used to create files. You need to change that line into Reset() and then the Reset() in your code is not necessary.
    :

    I changed the rewrite to reset & removed the second reset, but now I get the error "file not open for input". When I added it back in, it produces an endless loop of zero's. Any ideas?

    Thanks for your help.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories