So basically I was supposed to take my prior lab which read a text file that had the hours and wage:
15 10
50 15
30 10
I needed to add the name to my text file
Doe Jane 15 10
Doe John 50 15
Doe Joe 30 10
My problem comes when I wrote the following code
Readln(Infile, last, first, hours, wage);
Now I understand it has to do with the fact that I start with string variables so it confused the program by then having Real variables following.
So I tried to seperate the two
Readln(Infile, last, first);
Readln(Infile, hours, wage);
But then it will print the name but do an error 106 for the hours and wage.
I am confused and unfortunately my teacher is not very helpful (online class and she doesn't respond to emails). If someone could please explain what I should do or read that can explain this I would greatly appreciate it. The textbook the teacher assigned for the class is for pseudocode and its useless when I am trying to do pascal.
Thanks in advance for your help.
Program lab4;
Var
hours, hoursReg, hoursOver, wage, payReg, payOver, payGross, aveGross,
minGross, maxGross, totalGross: Real;
Count:Integer;
last, first: String;
Outfile,
Infile:Text;
LineCt:Integer;
firstTime, firstRecord:Boolean;
Const
timeAndHalf = 1.5;
PAGESIZE = 5;
Begin
Assign(Infile, 'C:\Users\Desktop\lab6.txt');
Reset(Infile);
Assign(Outfile, 'C:\Users\Desktop\out.txt');
Rewrite(Outfile);
LineCt := PAGESIZE + 1;
firstTime := True;
firstRecord := True;
count := 0;
totalGross := 0;
While Not EOF(Infile) Do
Begin
If LineCt >= PAGESIZE
Then
Begin
IF FirstTime
Then
FirstTime := False
Else
Write(Outfile, chr(12));
Writeln(Outfile, 'Name Regular Overtime Pay Regular Overtime Gross');
Writeln(Outfile, ' Hours Hours Rate Pay Pay Pay');
Writeln(Outfile);
LineCt := 3;
End;
Read(Infile, last, first, hours, wage);*********MY ERROR IS RIGHT HERE**********
If hours > 40 Then
Begin
hoursOver := hours - 40;
payOver := hoursOver * (wage * timeAndHalf);
End;
hoursReg := hours - hoursOver;
payReg := hoursReg * wage;
payGross := payReg + payOver;
If firstRecord
Then
Begin
minGross := payGross;
maxGross := payGross;
firstRecord := False;
End
Else
Begin
If minGross > payGross
Then
minGross := payGross;
If maxGross < payGross
Then
maxGross := payGross
End;
totalGross := totalGross + payGross;
count := count + 1;
Writeln(Outfile, last, first, hoursReg:0:2, hoursOver:9:2, wage:10:2, payReg:8:2, payOver:10:2,
payGross:10:2);
LineCt := +1;
End;
aveGross := totalGross / count;
Writeln(Outfile, '');
Writeln(Outfile, 'Total Gross Pay: ', totalGross:12:2);
Writeln(Outfile, 'Number of Employees: ', Count:5);
Writeln(Outfile, 'Average Gross Pay: ', aveGross:10:2);
Writeln(Outfile, 'Maximum Gross Pay: ', maxGross:10:2);
Writeln(Outfile, 'Minimum Gross Pay: ', minGross:10:2);
Close(Outfile);
Readln;
end.
hours, wage);
If hours > 40 Then
Begin
hoursOver := hours - 40;
payOver := hoursOver * (wage * timeAndHalf);
End;
hoursReg := hours - hoursOver;
payReg := hoursReg * wage;
payGross := payReg + payOver;
If firstRecord
Then
Begin
minGross := payGross;
maxGross := payGross;
firstRecord := False;
End
Else
Begin
If minGross > payGross
Then
minGross := payGross;
If maxGross < payGross
Then
maxGross := payGross
End;
totalGross := totalGross + payGross;
count := count + 1;
Writeln(Outfile, hoursReg:0:2, hoursOver:9:2, wage:10:2, payReg:8:2, payOver:10:2,
payGross:10:2);
LineCt := +1;
End;
aveGross := totalGross / count;
Writeln(Outfile, '');
Writeln(Outfile, 'Total Gross Pay: ', totalGross:12:2);
Writeln(Outfile, 'Number of Employees: ', Count:5);
Writeln(Outfile, 'Average Gross Pay: ', aveGross:10:2);
Writeln(Outfile, 'Maximum Gross Pay: ', maxGross:10:2);
Writeln(Outfile, 'Minimum Gross Pay: ', minGross:10:2);
Close(Outfile);
Readln;
end.