Reputation: 11
presently learning how to code in pascal and vba. Assisting my daughter who is preparing for examinations next year. I am stuck on a problem concerning her present assignment. After running the code the following errors were received:
main.pas(1,2) Fatal: Syntax error, "BEGIN" expected but "identifier N" found Fatal: Compilation aborted
Tried fixing the code, but as i said I have just started learning to code.
n: integer; (*n is ID number for each candidate*)
DV: integer; (*DV is the number of district votes available*)
VR: integer; (*VR is the number of votes received by the candidate in
the district*)
x: integer;
y: integer;
Divide: integer;
found: Boolean;
n: array[1..10] of integer; (*n is an array of 10 integers*)
Names: array[1…10] of string = (‘Richards’, ‘Gumbs’, ‘Carty’,
‘Fleming’, ‘Jones’, ‘Amorowat’, ‘De la cruz’, ‘Walker’,
‘Brooks’, ‘Baker’);
DV: array[1…10] of integer = (‘200’, ‘900’, ‘700’, ‘100’, ‘80’, ‘15’,
‘6, ‘20’, ‘50’, ‘1’);
VR: array[1…10] of integer = (‘50’, ‘700’, ‘600’, ‘20’, ‘30’, ‘2’,
‘6, ‘3’, ‘30’, ‘2’);
For x := 1 to 10 do
Begin
Repeat
Found:=false;
writeln('Enter Candidate ID Number: ’);
readln(n);
For y:= 1 to 10 do
if n = n[y] then
Found = true;
writeln(‘Name of Candidate is’ Names: array[1] ‘.’);
readln;
writeln(‘Number of votes available in the District is’
DV: array[1] ‘.’);
readln;
writeln(‘Number of votes received by the Candidate in the
District is’ VR: array[1] ‘.’);
readln;
Endif;
For y:= 1 to 10 do
if n = n[y] then
Divide:= (DV: array[1] DIV VR: array[1]);
Result:= Divide;
writeln(‘The percentage of votes received by’ Names:
array[1] ‘is’ Result ‘.’);
readln;
if Result:>= 0.20 then
writeln(‘The candidate,’ Names: array[1] ‘is to receive a
refund.’);
readln;
Elseif
writeln(‘The candidate,’ Names: array[1] ‘will not receive
a refund.’);
readln;
Endif;
Endif;
End;
The expected result is to choose a candidate by his ID number which would lead to his name, the number of vote available in a district and the number of votes the candidate obtained being displayed. it would then result in a calculation between the two vote counts (division) and if the percentage is greater than 20% he would receive a refund, if less than 20% he would not receive a refund. either result should be displayed.
Upvotes: 0
Views: 517
Reputation: 30715
I'm afraid that you q, as it currently stands, isn't really suited to SO because SO is really about specific (single) programming problems, not incrementally debugging source code (see Sertac's comment), nor providing online tutorials, which I think you probably need at this point. And I feel rather uncomfortable about posting this as an answer, because it isn't one in the normal SO sense. However it seems to me that you could use a few pointers:
Unless you absolutely have to use the online compiler, download and use a free online one like Free Pascal, which is well supported, uses standard Pascal syntax, and I'm sure there are basic first-time tutorials available. See here to download Lazarus, which is an excellent IDE for Free Pascal (which is included in the install) and here for an introductory tutorial.
Secondly, there are structural and syntactic elements of your source-code
which are definitely not standard Pascal, in particular endif
and elseif
.
Another example is that in standard Pascal, you have to surround a string (like your
Richards, etc) with single-quotes '
, not precede the string by a back-quote. This is very possibly the cause of your "illegal character" error
For a decent Free Pascal introductory tutorial see here and this youtube tutorial, both found by googling
"free pascal" introductory tutorial.
Fourthly, your online compiler ought to be complaining about the endif
abd elseif
s, the incorrectly string formatting and the fact that several of your variables are duplicated (DV
and VR
used as the names of an integer variable and an array, for example as in Pascal, identifiers within the same 'scope' need to have unique names (the fact that I should explain what 'scope' means is a sign that what the q needs is a tutorial).
Upvotes: 1