{ Assignment 5 }
{ Written by Bryan Bridges }

program assign05;

{ Declare Constants }
const
   Title1 = '           Pete''s Sweat Shop Payroll Information';
   Title2 = '             We Make It You Take It Corporation';
   Title3 = 'First Name  Last Name  Gender  Dependents  Hours  Rate   Wage';

{ Declare Variables }
var
   first_name : string [7];
   last_name : string [10];
   gender : char;
   dependents : integer;
   hours, rate, wages, deduction : real;
   Input, Output : text;

procedure OutputHeading;
begin
  { Write Header On Screen }
  writeln (Output, Title1);
  writeln (Output, Title2);
  writeln (Output, Title3);
end;

procedure ComputeWage(var salary : real);
begin
  { Regular & Overtime Wage Computing }
  if hours > 40 then
     salary := ((hours - 40.00) * rate * 1.50) + (40.00 * rate)
  else salary := (hours * rate);

  { Dependent Deduction Percentage }
  case dependents of
       1, 2, 3 : deduction := 0.01;
       4, 5 : deduction := 0.10;
       6, 7, 8, 9 : deduction := 0.15;
       10, 11, 12 : deduction := 0.20
  end;

  { Dependent Deductions }
  salary := salary * (1 - deduction);

  { Gender Additions }
  if (gender <> 'M') and (gender <> 'm') then
     salary := salary + 100.00
  else salary := salary + 75.00;
end;

procedure PrintResults(f_name : string);
   begin
   { Gender & Dependent Errors }
   if ((gender <> 'M') and (gender <> 'F')) and ((gender <> 'm') and (gender <> 'f')) then
      writeln (Output, gender, ' is an invalid gender type')
   else if (dependents < 0) or (dependents > 12) then
           writeln (Output, dependents, ' is an invalid dependent claim number')
   { Regular Output }
   else writeln (Output, f_name, last_name:15, gender:4, dependents:11, hours:10:1, rate:7:2, wages:8:2);
   end;

{ Start Main Program }
begin

{ Assign Input & Output Files }
   assign (Input, 'D:\FILES\BAB''S\PASCAL\ASSIGN05.INP');
   reset (Input);
   assign (Output, 'D:\FILES\BAB''S\PASCAL\ASSIGN05.OUT');
   rewrite (Output);

OutputHeading;

while not EOF (Input) do
   begin
   { Read Input File }
   readln (Input, first_name, last_name, gender, dependents, hours, rate);
   { Wage Computing }
   ComputeWage(wages);
   { Write Output File }
   PrintResults(first_name);
   end;

{ End Main Program }
end.
