0

I am new to Pascal and I am trying to write a program for my college assignment, but i am getting compile errors which say:

[dcc32 Error] Project2.dpr(36): E2029 ';' expected but '.' found

[dcc32 Error] Project2.dpr(38): E2029 Declaration expected but end of file found

Here is the program I have written:

program masquerader;  //program name

Var //Declaring variables

  Salary:integer; //Declared Salary as integer

procedure Sleep(milliseconds: Cardinal); stdcall;//Added sleep as a procedure for delay

Begin      //Begins the program

  Writeln('Enter Your Salary please user...'); //Outputs line Enter Your salary please user...
  Readln(Salary); //Recieves the value and declares the integer value to salary
  Writeln('Processing your input...'); //Outputs line to Let the user know its being processed
  Sleep(4000);  //4 second delay
  Writeln('Done!');
  If (Salary>=5000) AND (Salary<=8000) Then //Conditions are being test for the requirements for each section
    Writeln('Thanks for your Input file should be ready in a second'); //  Outputs this line to let the user know it is ready in a second
    Writeln('Congratulations!,You are eligible to play in poison');    //Outputs the section that matches the user's salary(5000-8000)
  If (Salary>=3000) AND (Salary<=5000) Then //Conditions are being test for the requirements for each section
    Writeln('Thanks for your Input file should be ready in a second'); //  Outputs this line to let the user know it is ready in a second
    Writeln('Congratulations!,You are eligible to play in Blue devils');//Outputs the section that matches the user's salary(3000-5000)
  If (Salary<3000) Then  //Conditions are being test for the requirements for each section
    Writeln('Thanks for your Input file should be ready in a second'); //  Outputs this line to let the user know it is ready in a second
    Writeln('Congratulations!,You are eligible to play in The poor man section');//Outputs the section that matches the user's salary(x<=3000)
    Writeln('Written by Timothy Adams');
    Writeln('Fatima College 4-1');
    Readln; //Declares the end of the read line

End.   //End of program       //Program written by timothy Adams
3
  • I fixed it by removing the procedure and the sleep line but i need it for the assignment...is there any other way to add a delay? around 5 seconds delay Commented Mar 1, 2020 at 16:03
  • Get sleep by using the function declared in Windows.pas. So remove the declaration of sleep in your code and use Windows. Commented Mar 1, 2020 at 17:14
  • So this user deleted his account. I wonder why SO. Commented Mar 2, 2020 at 16:13

1 Answer 1

4

There are a number of problems with your code.

You are declaring a new function Sleep() without telling the compiler where its implementation is. So the compiler thinks your entire code between begin and end is the implementation. That is why you are getting the errors, because you are terminating the function implementation with end. instead of end;

The Sleep() function your are trying to use is already declared in the RTL's Windows unit, use that instead. But, if you want to declare Sleep() manually then you need to include an external clause to tell the compiler that the implementation is located in a DLL (specifically, in kernel32.dll). That will then allow the compiler to treat your begin/end block as the program implementation instead.

Also, Delphi code blocks are not specified by indentation, like you are assuming. You need to use explicit begin/end statements to group statements together.

Try this instead:

program masquerader; //program name

uses
  Windows;

Var //Declaring variables
  Salary:integer; //Declared Salary as integer

//procedure Sleep(milliseconds: Cardinal); stdcall; external 'kernel32.dll'; //Added sleep as a procedure for delay

Begin //Begins the program

  Writeln('Enter Your Salary please user...'); //Outputs line Enter Your salary please user...
  Readln(Salary); //Recieves the value and declares the integer value to salary Writeln('Processing your input...'); //Outputs line to Let the user know its being processed
  Sleep(4000); //4 second delay
  Writeln('Done!');

  If (Salary>=5000) AND (Salary<=8000) Then //Conditions are being test for the requirements for each section
  Begin
    Writeln('Thanks for your Input file should be ready in a second'); // Outputs this line to let the user know it is ready in a second
    Writeln('Congratulations!,You are eligible to play in poison'); //Outputs the section that matches the user's salary(5000-8000)
  End;

  If (Salary>=3000) AND (Salary<=5000) Then //Conditions are being test for the requirements for each section
  Begin
    Writeln('Thanks for your Input file should be ready in a second'); // Outputs this line to let the user know it is ready in a second
    Writeln('Congratulations!,You are eligible to play in Blue devils');//Outputs the section that matches the user's salary(3000-5000)
  End;

  If (Salary<3000) Then //Conditions are being test for the requirements for each section
  Begin
    Writeln('Thanks for your Input file should be ready in a second'); // Outputs this line to let the user know it is ready in a second
    Writeln('Congratulations!,You are eligible to play in The poor man section');//Outputs the section that matches the user's salary(x<=3000)
  End;

  Writeln('Written by Timothy Adams');
  Writeln('Fatima College 4-1');
  Readln; //Declares the end of the read line

End. //End of program
//Program written by timothy Adams

On a side note, your code is not handling salaries above 8000.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much this worked very well thank you, im new to programming and this was my first project which i find pascal being an outdated language but thank you for your help.
"i find pascal being an outdated language" - hardly, certainly not the Delphi flavor of Pascal, anyway. Delphi is in the top 20 popular languages of the TIOBE index, for instance
i didnt know that honestly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.