Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

I am supposed to find the gross pay for 5 employees but my program is not running. What is the problem

–1 vote
asked Apr 21, 2021 by Teara Griffiths (110 points)
{This program is to calculate the gross pay of 5 employees
//Teara Griffiths
//GRIFFITHS ACCOUNTING FIRM
//April 5,2021}
PROGRAM Payment;
uses crt;
var
   first_name,last_name:Array[1..5] of CHAR;
   employee_level:Array [1..5] of INTEGER;
   hours_worked:Array [1..5] of REAL;
   overtime_pay:Array [1..5] of REAL;
   hourly_rate:Array [1..5] of REAL;
   gross_pay:Array [1..5] of REAL;

   Const
     LEVEL1=525;
     LEVEL2=1800;
     LEVEL3=2000;
     RATE=1.5;

BEGIN
     writeln('Please enter first name,last name.');
     readln(first_name,last_name);
     writeln('Please enter employee level.');
     readln(employee_level);
     writeln('Please enter employee hours worked.');
     readln(hours_worked);
     writeln('Please enter employee overtime pay.');
     readln(overtime_pay);
     writeln('Please enter employee hourly rate.');
     readln(hourly_rate);

     IF hours_worked>40 THEN
          begin
                (hours_worked*hourly_rate)+(overtime_pay*1.5):=gross_pay;
                writeln('gross_pay');
                readln(gross_pay);
          end;
     ELSE
         begin
               hours_worked*hourly_rate:=gross_pay;
           writeln('gross_pay');
           readln;(gross_pay)
          end;
     ENDIF
END.

1 Answer

0 votes
answered Apr 28, 2021 by Peter Minarik (86,640 points)

This code has a lot of problems. Not just syntax but also logic issues.

  • [LOGIC] First of all, you have arrays, but you treat them as scalars (simple variables, not arrays). I don't see why you'd need arrays for this problem
  • [SYNTAX] Your if-else has wrong syntax (; mustn't be added before else and there's no such thing as ENDIF if Pascal)
  • [LOGIC] After you calculate the gross_pay, you read it from the user, instead of printing it to the user.
  • [SYNTAX] you can assign values to variables like this: gross_pay := _____; (and not ____ := gross_pay)
I'll assume you'll need the arrays later and your code is just not finished yet. So I'll publish my fix using the arrays:
PROGRAM Payment;
uses crt;
var
    first_name,last_name:Array[1..5] of CHAR;
    employee_level:Array [1..5] of INTEGER;
    hours_worked:Array [1..5] of REAL;
    overtime_pay:Array [1..5] of REAL;
    hourly_rate:Array [1..5] of REAL;
    gross_pay:Array [1..5] of REAL;

Const
    LEVEL1=525;
    LEVEL2=1800;
    LEVEL3=2000;
    RATE=1.5;

BEGIN
    writeln('Please enter first name,last name.');
    readln(first_name, last_name);
    writeln('Please enter employee level.');
    readln(employee_level[1]);
    writeln('Please enter employee hours worked.');
    readln(hours_worked[1]);
    writeln('Please enter employee overtime pay.');
    readln(overtime_pay[1]);
    writeln('Please enter employee hourly rate.');
    readln(hourly_rate[1]);

    IF hours_worked[1] > 40 THEN
        begin
            gross_pay[1] := (hours_worked[1] * hourly_rate[1]) + (overtime_pay[1] * 1.5);
        end
    ELSE
        begin
            gross_pay[1] := hours_worked[1] * hourly_rate[1];
        end;
    writeln('gross_pay');
    writeln(gross_pay[1]);
END.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...