Recent

Author Topic: Fatal : Syntax error  (Read 673 times)

ilhamrizki25

  • New member
  • *
  • Posts: 5
Fatal : Syntax error
« on: September 05, 2018, 08:21:00 am »
Hi guys
I'm new to Programming, and I have an assignment that keep me stuck. Can you guys help me?
Here's the code :

Program IFLAB;
uses crt;
TYPE karyawan = record nama : String;
jml_lembur,gol : integer;
    gaji_pokok,bonus_tetap,bonus_lembur,gaji_bulan,gaji_total: integer;

end;

var
 a : karyawan

begin
clrscr;

 writeln('Masukkan nama karyawan : '); readln(a.nama);
 writeln('Golongan Karyawan : ');
 writeln('       1. Golongan I ');
 writeln('       2. Golongan II ');
 writeln('       3. Golongan III ');
 writeln('Masukkan golongan karyawan : '); readln(a.gol);
 writeln('Masukkan jumlah lembur : '); readln(a.jml_lembur);
 case a.gol of
        1 : begin
                a.gaji_pokok := 250000;
            end;
        2 : begin
                a.gaji_pokok := 500000;
            end;
        3 : begin
                a.gaji_pokok := 750000;
            end;
a.bonus_tetap := 0.25*a.gaji_pokok;
a.bonus_lembur := a.jml_lembur*a.bonus_tetap;
a.gaji_bulan:= a.gaji_pokok+a.bonus_tetap+a.bonus_lembur;
writeln('---Jumlah Gaji---');
writeln('Nama Karyawan  : ',a.nama);
writeln('Golongan Karyawan : ',a.gol);
writeln('Jumlah lembur : ',a.jml_lembur);
writeln('Total Gaji per Bulan : Rp. ',a.gaji_bulan:0:0); readln;
end.

it always said (12,1) Fatal : Syntax error, ";" expected but BEGIN found

bytebites

  • Full Member
  • ***
  • Posts: 164
Re: Fatal : Syntax error
« Reply #1 on: September 05, 2018, 08:35:45 am »
Do what error message suggests.

440bx

  • Sr. Member
  • ****
  • Posts: 391
Re: Fatal : Syntax error
« Reply #2 on: September 05, 2018, 08:42:29 am »
look carefully, there is a semicolon missing before the "begin" statement.

Handoko

  • Hero Member
  • *****
  • Posts: 2691
  • My goal: build my own game engine using Lazarus
Re: Fatal : Syntax error
« Reply #3 on: September 05, 2018, 09:30:40 am »
Actually there are 4 bugs.

Below is the source code after formatted and added code tag:

Code: Pascal  [Select]
  1. program IFLAB;
  2.  
  3. uses crt;
  4.  
  5. type
  6.  
  7.   karyawan = record
  8.     nama : String;
  9.     jml_lembur,gol : integer;
  10.     gaji_pokok,bonus_tetap,bonus_lembur,gaji_bulan,gaji_total: integer;
  11.   end;
  12.  
  13. var
  14.  a : karyawan
  15.  
  16. begin
  17.  
  18.   clrscr;
  19.   writeln('Masukkan nama karyawan : '); readln(a.nama);
  20.   writeln('Golongan Karyawan : ');
  21.   writeln('       1. Golongan I ');
  22.   writeln('       2. Golongan II ');
  23.   writeln('       3. Golongan III ');
  24.   writeln('Masukkan golongan karyawan : '); readln(a.gol);
  25.   writeln('Masukkan jumlah lembur : '); readln(a.jml_lembur);
  26.  
  27.   case a.gol of
  28.         1 : begin
  29.                 a.gaji_pokok := 250000;
  30.             end;
  31.         2 : begin
  32.                 a.gaji_pokok := 500000;
  33.             end;
  34.         3 : begin
  35.                 a.gaji_pokok := 750000;
  36.             end;
  37.  
  38.   a.bonus_tetap  := 0.25*a.gaji_pokok;
  39.   a.bonus_lembur := a.jml_lembur*a.bonus_tetap;
  40.   a.gaji_bulan   := a.gaji_pokok+a.bonus_tetap+a.bonus_lembur;
  41.  
  42.   writeln('---Jumlah Gaji---');
  43.   writeln('Nama Karyawan  : ',a.nama);
  44.   writeln('Golongan Karyawan : ',a.gol);
  45.   writeln('Jumlah lembur : ',a.jml_lembur);
  46.   writeln('Total Gaji per Bulan : Rp. ',a.gaji_bulan:0:0);
  47.   readln;
  48.  
  49. end.

Bug 1
You need a semicolon at the end of line #14.

Bug 2
The case block needs an end. See line #27.

Bug 3
a.bonus_tetap is an integer, it cannot accept decimal result of the operation on line #38.

Bug 4
a.gaji_bulan is an integer, it cannot use decimal format for writeln on line #46.

@ilhamrizki25
You should use code tag when posting source code on this forum. Read more:
http://wiki.lazarus.freepascal.org/Forum

ilhamrizki25

  • New member
  • *
  • Posts: 5
Re: Fatal : Syntax error
« Reply #4 on: September 05, 2018, 01:15:26 pm »
Actually there are 4 bugs.

Below is the source code after formatted and added code tag:

Code: Pascal  [Select]
  1. program IFLAB;
  2.  
  3. uses crt;
  4.  
  5. type
  6.  
  7.   karyawan = record
  8.     nama : String;
  9.     jml_lembur,gol : integer;
  10.     gaji_pokok,bonus_tetap,bonus_lembur,gaji_bulan,gaji_total: integer;
  11.   end;
  12.  
  13. var
  14.  a : karyawan
  15.  
  16. begin
  17.  
  18.   clrscr;
  19.   writeln('Masukkan nama karyawan : '); readln(a.nama);
  20.   writeln('Golongan Karyawan : ');
  21.   writeln('       1. Golongan I ');
  22.   writeln('       2. Golongan II ');
  23.   writeln('       3. Golongan III ');
  24.   writeln('Masukkan golongan karyawan : '); readln(a.gol);
  25.   writeln('Masukkan jumlah lembur : '); readln(a.jml_lembur);
  26.  
  27.   case a.gol of
  28.         1 : begin
  29.                 a.gaji_pokok := 250000;
  30.             end;
  31.         2 : begin
  32.                 a.gaji_pokok := 500000;
  33.             end;
  34.         3 : begin
  35.                 a.gaji_pokok := 750000;
  36.             end;
  37.  
  38.   a.bonus_tetap  := 0.25*a.gaji_pokok;
  39.   a.bonus_lembur := a.jml_lembur*a.bonus_tetap;
  40.   a.gaji_bulan   := a.gaji_pokok+a.bonus_tetap+a.bonus_lembur;
  41.  
  42.   writeln('---Jumlah Gaji---');
  43.   writeln('Nama Karyawan  : ',a.nama);
  44.   writeln('Golongan Karyawan : ',a.gol);
  45.   writeln('Jumlah lembur : ',a.jml_lembur);
  46.   writeln('Total Gaji per Bulan : Rp. ',a.gaji_bulan:0:0);
  47.   readln;
  48.  
  49. end.

Bug 1
You need a semicolon at the end of line #14.

Bug 2
The case block needs an end. See line #27.

Bug 3
a.bonus_tetap is an integer, it cannot accept decimal result of the operation on line #38.

Bug 4
a.gaji_bulan is an integer, it cannot use decimal format for writeln on line #46.

@ilhamrizki25
You should use code tag when posting source code on this forum. Read more:
http://wiki.lazarus.freepascal.org/Forum

Thank you for your help, sir. And yes, my bad, I won't do the same mistake again in future
I hope at least