Recent

Author Topic: Pascal, Compiler error. Fatal: Unexpected end of file  (Read 2360 times)

coder

  • Newbie
  • Posts: 1
Pascal, Compiler error. Fatal: Unexpected end of file
« on: October 30, 2021, 01:16:14 am »
Hi guys. I've just started learning Pascal in school in this is one of the codes we had to create to find salary. the teacher gave us the information and we had to make the code in pascal. I wrote this code in pascal and when I compiled it I got the "Fatal: Unexpected end to file" error so i was wondering if you guys can tell me what is wrong.

Code: Pascal  [Select][+][-]
  1. [program Salary;
  2. uses crt;
  3. var
  4. HW,HR: Integer;
  5. NumC: Integer;
  6. GS,NS: Integer;
  7.  
  8. Begin
  9. clrscr;
  10.  
  11. Writeln('Enter hours worked');
  12.         Readln(HW);
  13.  
  14. Writeln('Enter hourly rate');
  15.        Readln(HR);
  16. GS:= HW * HR;
  17.  
  18.    If NumC > 0 then
  19. (* If value is true then print the following* )
  20.       GS:= (GS + (0 + GS)*40)
  21. else
  22. (* If value is false then print the following* )
  23.   GS:= (HW * HR);
  24.        Readln(GS);
  25.  
  26.   If GS> 20000 then
  27. (* If value is true then print the following* )
  28.     NS:= (* GS subtract (GS * 0.15)* )
  29.     readln(NS);
  30. else
  31. (* If value is false then print the following* )
  32.     Ns:= GS
  33. writeln(' The Gross Salary is ' , GS);
  34.    Readln(GS);
  35.  
  36. Writeln('The Net Salary is ' , NS)
  37.    Readln(NS);
  38.  
  39. End.
  40. ]
  41.  
  42.  

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: Pascal, Compiler error. Fatal: Unexpected end of file
« Reply #1 on: October 30, 2021, 01:44:34 am »
It now compiles, but the program doesn't work.

The main problem was there [ code ] brackets and comments (* * ) instead of (* *)

Code: Pascal  [Select][+][-]
  1. program Salary;
  2. uses crt;
  3. var
  4. HW,HR: Integer;
  5. NumC: Integer;
  6. GS,NS: Integer;
  7.  
  8. Begin
  9. clrscr;
  10.  
  11. Writeln('Enter hours worked');
  12.         Readln(HW);
  13.  
  14. Writeln('Enter hourly rate');
  15.        Readln(HR);
  16. GS:= HW * HR;
  17.  
  18.    If NumC > 0 then
  19. (* If value is true then print the following *)
  20.       GS:= (GS + (0 + GS)*40)
  21. else
  22. (* If value is false then print the following *)
  23.   GS:= (HW * HR);
  24.        Readln(GS);
  25.  
  26.   If GS> 20000 then
  27. (* If value is true then print the following *)
  28.      (* GS subtract (GS * 0.15) *)
  29.      readln(NS)
  30. else
  31. (* If value is false then print the following *)
  32.     Ns:= GS;
  33. writeln(' The Gross Salary is ' , GS);
  34.    Readln(GS);
  35.  
  36. Writeln('The Net Salary is ' , NS);
  37.    Readln(NS);
  38.  
  39. End.

[Edited to fix code tags.]
« Last Edit: October 30, 2021, 02:03:55 am by trev »

dbannon

  • Hero Member
  • *****
  • Posts: 2796
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Pascal, Compiler error. Fatal: Unexpected end of file
« Reply #2 on: October 30, 2021, 01:44:58 am »
coder, are you using an editor that shows the syntax ?  Even the forum here shows there is something quite seriously wrong in the tail end of your code.

A couple of places to start -

* Comments are great, use them ! But you seem to be putting a space between the * and the brackets. Mybe think about using // and { } as comment markers (depending on your compiler), they can be a touch more readable.
* you seem to have a square bracket after the "end." ??

Code: Pascal  [Select][+][-]
  1.    If GS> 20000 then
  2. (* If value is true then print the following*)
  3.     NS:= (* GS subtract (GS * 0.15)* )
  4.     readln(NS);
  5. else ....
  6.  

should be line this

Code: Pascal  [Select][+][-]
  1. If GS> 20000 then
  2.     (* If value is true then print the following*)
  3.     NS:= (* GS subtract (GS * 0.15)*)
  4.     readln(NS);
  5. else ....

I am not sure about your programme flow, with the funny comments its a bit hard to see what you are trying to do.


Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dseligo

  • Hero Member
  • *****
  • Posts: 1221
Re: Pascal, Compiler error. Fatal: Unexpected end of file
« Reply #3 on: October 30, 2021, 02:00:06 am »
1. You have square brackets in line 1 and line 40. Delete those.
2. Delete space between '*' and ')' when closing comments in lines 19, 22, 27, 28 and 31.
3. In line 26 you start if-then-else branch. There are several issues here. If there is more than one statement you need to enclose it in begin/end block. In line 28 you don't have an expression to assign to 'NS:='. In line 32 you miss semicolon in the end of line.
4. In line 36 you also miss semicolon in the end of line.

Now your program should compile, but it probably won't work as you hope.
E.g. you use NumC variable and you didn't initialize it (or calculate it).
In several places you read variables GS and NS from keyboard (ReadLn). I assume you should calculate those variables.
In one comment you have multiplying with decimal number (0.25). If you will use decimal numbers in your calculations you should use 'real' instead of 'integer' when declaring those variables.

Probably more problems will surface, but try to fix these for now.

 

TinyPortal © 2005-2018