Recent

Author Topic: Pascal error troubleshooting  (Read 398 times)

Techintel

  • Newbie
  • Posts: 4
Pascal error troubleshooting
« on: May 23, 2020, 02:38:28 am »
Greeting all, I hope everyone is staying safe.

I am kindly asking for some help... to get my code running
- Thanks



program Refund Status;
Var
Candidates:  integer;
RefundsReceived: integer;
CandidateName:  string;
VotesReceived:  integer;
VotesCast:  integer;
Percentage:  real;


Begin
   writeln(‘Welcome’)
   writeln(‘Enter appropriate responses for an accurate result’)
   for Candidates:=1 to 10 do
    begin
      writeln(‘Enter Candidate name’);
      readln(CandidateName);
      writeln;
      writeln(‘Enter Candidate votes received’);
      readln(VotesReceived);
      writeln;
      writeln(‘Enter Constituency’s Votes Cast’);
      readln(VotesCast)
      writeln;
      Percentage  :=(Candidate’sVotesReceived/Constituency’sVotesVast)*100;
      writeln;
              if Percentage>=20% then
   begin
      writeln(‘Refund Due for ’,Candidate’sName);
      Candidates  := Candidates + 1
   end
             else
   begin
      writeln(‘No Refund’)
   end;
    end;
      writeln(‘The number of candidates who received a refund is ’,RefundsReceived);
End.

jamie

  • Hero Member
  • *****
  • Posts: 2935
Re: Pascal error troubleshooting
« Reply #1 on: May 23, 2020, 03:31:00 am »
I can see this is a school project  :D

First off, use    ' your text '   instead of what you are doing...don't use ` and the other one I can't seem to reproduce from my keyboard.

 come back when you have that one figured out and put your code within a pound symbol as you can see above " # "

Thank you for your services, have a nice day.
Number 1 at blue screen app creations!

Techintel

  • Newbie
  • Posts: 4
Re: Pascal error troubleshooting
« Reply #2 on: May 23, 2020, 04:25:23 am »
Noted. Thanks.

TRon

  • Full Member
  • ***
  • Posts: 101
Re: Pascal error troubleshooting
« Reply #3 on: May 23, 2020, 05:34:37 am »
Please help... I attached a screenshot with the error messages
As said, use code-tags (https://wiki.freepascal.org/Forum#Use_code_tags). The very first character is throwing you an error but we have no way of knowing what that character might be.

Code: Pascal  [Select][+][-]
  1. program RefundStatus;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes
  10.   { you can add units after this };
  11.  
  12. begin
  13.  
  14.  
  15.       Program RefundStatus;
  16.  
  17. Var
  18.  
  19.     Candidates:integer;
  20.     RefundsReceived: integer;
  21.     CandidateName:  string;
  22.     VotesReceived:  integer;
  23.     VotesCast:  integer;
  24.     Percentage:  real;
  25.  
  26.     begin candidates:=1;
  27.  
  28.  
  29. Begin
  30.         for Candidates:=1 to 10 do ;
  31.  
  32.         Write('Welcome');
  33.         Write('Enter appropriate responses for an accurate result');
  34.  
  35.         for Candidates:=1 to 10 do ;
  36.          begin
  37.                 writeln('Enter Candidate name');
  38.                 readln(CandidateName);
  39.                 writeln;
  40.                 writeln('Enter Candidate votes received');
  41.                 readln(VotesReceived);
  42.                 writeln;
  43.                 writeln('Enter Constituency Votes Cast');
  44.                 readln(VotesCast);
  45.                 Writeln;
  46.                 Percentage  :=(VotesReceived/ VotesCast)*100;
  47.                 writeln;
  48.               if Percentage>=20 then
  49.         begin
  50.                 writeln('Refund Due for' , 'Candidates Name');
  51.                 Candidates  := Candidates + 1
  52.         end
  53.              else
  54.  
  55.         begin
  56.                 writeln('No Refund')
  57.         end;
  58.          end;
  59.                 writeln('The number of candidates who received a refund is ', 'RefundsReceived');
  60. End;
  61.  
  62.  
  63.  
  64. end.
  65.  

edit:
And when there is no (strange) character messing things up the fpc commandline compiler throws:
Code: [Select]
Compiling RefundStatus.pas
RefundStatus.pas(15,7) Error: Illegal expression
RefundStatus.pas(15,15) Fatal: Syntax error, ";" expected but "identifier REFUNDSTATUS" found
Fatal: Compilation aborted
Error: ppcarm returned an error exitcode
Compilation failed.

Which is to be expected  :)

In case you might be wondering why then please read https://wiki.freepascal.org/Program_Structure and https://wiki.lazarus.freepascal.org/Program so that you are able to address the issue.

« Last Edit: May 23, 2020, 06:03:34 am by TRon »

Techintel

  • Newbie
  • Posts: 4
Re: Pascal error troubleshooting
« Reply #4 on: May 23, 2020, 06:10:54 am »
Thanks TRon

Techintel

  • Newbie
  • Posts: 4
Re: Pascal error troubleshooting
« Reply #5 on: May 23, 2020, 06:32:27 am »
I added the tags for clarity

Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. program RefundStatus;
  4.  
  5. {$mode objfpc}{$H+}
  6.  
  7. uses
  8.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  9.   cthreads,
  10.   {$ENDIF}{$ENDIF}
  11.   Classes
  12.   { you can add units after this };
  13.  
  14. begin
  15.  
  16.  
  17.       Program RefundStatus;
  18.  
  19. Var
  20.  
  21.     Candidates:integer;
  22.     RefundsReceived: integer;
  23.     CandidateName:  string;
  24.     VotesReceived:  integer;
  25.     VotesCast:  integer;
  26.     Percentage:  real;
  27.  
  28.     begin candidates:=1;
  29.  
  30.  
  31. Begin
  32.         for Candidates:=1 to 10 do ;
  33.  
  34.         Write('Welcome');
  35.         Write('Enter appropriate responses for an accurate result');
  36.  
  37.         for Candidates:=1 to 10 do ;
  38.          begin
  39.                 writeln('Enter Candidate name');
  40.                 readln(CandidateName);
  41.                 writeln;
  42.                 writeln('Enter Candidate votes received');
  43.                 readln(VotesReceived);
  44.                 writeln;
  45.                 writeln('Enter Constituency Votes Cast');
  46.                 readln(VotesCast);
  47.                 Writeln;
  48.                 Percentage  :=(VotesReceived/ VotesCast)*100;
  49.                 writeln;
  50.               if Percentage>=20 then
  51.         begin
  52.                 writeln('Refund Due for' , 'Candidates Name');
  53.                 Candidates  := Candidates + 1
  54.         end
  55.              else
  56.  
  57.         begin
  58.                 writeln('No Refund')
  59.         end;
  60.          end;
  61.                 writeln('The number of candidates who received a refund is ', 'RefundsReceived');
  62. End;
  63.  
  64.  
  65.  
  66. end.
  67.  

TRon

  • Full Member
  • ***
  • Posts: 101
Re: Pascal error troubleshooting
« Reply #6 on: May 23, 2020, 06:38:21 am »
Thanks TRon
If you are able to 'fix' the structural issues, then we can help you with actual implementation related issues.

Because you are doing a homework assignment we simply can't provide a literal answer (well, we could but what good would that do you).

That means that in case your code isn't exactly doing what you expected it to do then please ask explicit questions (even if you do not know the exact words, then try to describe it), by describing the problem (what you have written, what you expected the code to do and what the code is actually doing (wrong) for you. That way you are able to get the quickest answer (and learn the fastest).

Quote
I added the tags for clarity
There you go, looking a lot nicer don't you think ? :-)

Are you still presented with the same error ? Because that could suggest there is something wrong that is not even related to code whatsoever.

fwiw: if i copy-paste the code (between the code-tags) you just posted then there is nothing wrong with it. In worst case, copy-paste it yourself back in your editor and save it before compiling.

trev

  • Hero Member
  • *****
  • Posts: 668
  • Former Delphi 1-7 and 10.2 User
Re: Pascal error troubleshooting
« Reply #7 on: May 23, 2020, 09:22:10 am »
For help with the structural issues in the program code, you could start with the Wiki's Basic Pascal Tutorial's "Hello, World" and the pages that follow.
o Lazarus v2.1.0 r63272, FPC v3.3.1 r45525, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 (Parallels VM)
o FPC 3.0.4, FreeBSD 12-STABLE r358002
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

mika

  • Newbie
  • Posts: 3
Re: Pascal error troubleshooting
« Reply #8 on: May 23, 2020, 11:12:26 am »
Quote
I am kindly asking for some help... to get my code running

Tehnicly you did it yourself.
Your version of running code:
Code: Pascal  [Select][+][-]
  1. Program RefundStatus;
  2.  
  3. Var
  4.  
  5.     Candidates:integer;
  6.     RefundsReceived: integer;
  7.     CandidateName:  string;
  8.     VotesReceived:  integer;
  9.     VotesCast:  integer;
  10.     Percentage:  real;
  11.  
  12. begin candidates:=1;
  13.  
  14.  
  15.  
  16.         for Candidates:=1 to 10 do ;
  17.  
  18.         Write('Welcome');
  19.         Write('Enter appropriate responses for an accurate result');
  20.  
  21.         for Candidates:=1 to 10 do ;
  22.          begin
  23.                 writeln('Enter Candidate name');
  24.                 readln(CandidateName);
  25.                 writeln;
  26.                 writeln('Enter Candidate votes received');
  27.                 readln(VotesReceived);
  28.                 writeln;
  29.                 writeln('Enter Constituency Votes Cast');
  30.                 readln(VotesCast);
  31.                 Writeln;
  32.                 Percentage  :=(VotesReceived/ VotesCast)*100;
  33.                 writeln;
  34.               if Percentage>=20 then
  35.         begin
  36.                 writeln('Refund Due for' , 'Candidates Name');
  37.                 Candidates  := Candidates + 1
  38.         end
  39.              else
  40.  
  41.         begin
  42.                 writeln('No Refund')
  43.         end;
  44.          end;
  45.                 writeln('The number of candidates who received a refund is ', 'RefundsReceived');
  46. end.
  47.  

1.
To fix it further you have to answer to yourself "what code suppose to do and what output suppose to be?"

2. there are 3 types of ";"  a) statement must end with ";" b) ";" is optional at end of statement c) program behavior dramatically changes by having or not having ";" at the end of the statement

3. learn how to output value of variable (it's most important thing  if your goal is to learn programing at all)

4.
Code: Pascal  [Select][+][-]
  1. Candidates  := Candidates + 1
from compiler stand point line is correct. Is it thou?

 

TinyPortal © 2005-2018