How to solve this syntax error, "identifier" expected but "ordinal const" found? - pascal

(14,22) Error: Illegal qualifier
(14,22) Fatal: Syntax error, "identifier" expected but "ordinal const" found
PROGRAM menentukan_bonus_karyawan;
uses crt;
var
nama, golongan: string;
lama_kerja : integer;
bonus : real;
begin
clrscr;
write('Masukkan nama anda : '); readln(nama);
write('Golongan karyawan (staf/ non-staf) : '); readln(golongan);
write('Lama kerja : '); readln(lama_kerja);
case (golongan) of
'staf' : if lama_kerja >= 10 then
bonus := 1.000.000 <--- error line
else
bonus := 700.000;
'non-staf' : if lama_kerja >= 10 then
bonus := 500.000
else
bonus := 350.000;
end;
writeln('Saudara ', nama, ' dengan golongan karyawan ', golongan, ' mendapatkan bonus sebesar Rp. ', bonus);
readln;
end.

The problem is that the value of 1.000.000 is invalid. If you meant one million, then you should use 1000000. If you wanted one thousand, then you could use 1000.000.

Related

How do I concatenate values from 2 fields into one field

I'm trying to concatenate 2 fields (Name and Other names) into one variable. For example, if my name is Jeffrey and other name is Johnston the the result should be Jeffrey Johnston.
I have tried the following on PRE-TEXT-ITEM
BEGIN
:LOAN.NAME := ':LOAN.NAME :LOAN.OTHER_NAMES';
END;
BEGIN
:LOAN.NAME := :LOAN.NAME + ' ' + :LOAN.OTHER_NAMES;
END;
When trying the following code
BEGIN
:LOAN.NAME := :LOAN.NAME + ' ' + :LOAN.OTHER_NAMES;
END;
I received this error message:
FRM-40735: PRE-TEXT-ITEM trigger raised unhandled exception ORA-06502
You should use ||
BEGIN
:LOAN.NAME := :LOAN.NAME || ' ' || :LOAN.OTHER_NAMES;
END;

Pascal : fatal syntax error

Trying to execute catalan numbers in Pascal but getting fatal syntax error.
Error is :
Fatal: Syntax error, ";" expected but "identifier B" found
Error: /usr/bin/ppcx64 returned an error exitcode
Here is ref code
program main;
var
i,buf: integer;
function catalan(num: integer): integer;
var
sample, returnval : integer;
function bincoeff(n: integer): integer;
var
a,b,retval,numr,denom1,denom2: integer;
bc : integer;
function fact(x: integer): integer;
begin
// fact exec
if x=0 then
fact :=1
else
fact := x* fact(x-1);
end;
begin
//bincoeff exec
a := 2*n
b := n
if a==b then
retval :=1
else if b>a
retval :=0
else
numr := fact(a)
denom1 := fact(b)
denom2 := fact(a-b)
bc := numr /(denom1*denom2)
retval := bc
end;
begin
// catalan exec
sample :=bincoeff(num)
returnval := (sample/(num+1))
end;
begin
for i :=0 to 9 do
begin
buf := catalan(i)
writeln(buf)
end;
end.
Starting with
a := 2*n
till the end of the program you systematically don't use ';'. A fact that, by the way, is signaled pretty clearly by the compiler.
In this context it might be interesting to visit the FreePascal wiki on the topic of the semicolon which points out an important difference between C and Pascal's usage of the semicolon (separator vs terminator). A must-read.

unknown runtime error in pascal

I am unable to locate the source of this error that i keep getting in my coding for school. Every time i enter one value in my array and the for loop runs it either encounters a runtime error or the rest of the program runs based on information from the first value and doesn't accept any other values. Can someone please explain to me how to fix this?
program Montserrat_Elections;
Var cndnme : array [1..4] of String;
votes : array [1..4] of Integer;
highest, cnt : Integer;
winner : string;
begin
highest:= 0;
winner:= 'Dan';
For cnt:= 1 to 4 do
begin
Writeln('Please enter the first name of the candidate and the number of votes');
Read (cndnme[cnt], votes[cnt]);
If votes[cnt] > highest then
highest := votes[cnt];
winner := cndnme[cnt];
end;
Writeln('The winner of this constituency is', winner, 'with', highest, 'votes')
end.
Change Read to Readln :
Readln (cndnme[cnt], votes[cnt]);
Then you need add begin...end; to this line:
If votes[cnt] > highest then
begin
highest := votes[cnt];
winner := cndnme[cnt];
end;
I update & test your codes :
program Montserrat_Elections;
Var cndnme : array [1..4] of String;
votes : array [1..4] of Integer;
highest, cnt : Integer;
winner : string;
begin
highest:= 0;
winner:= 'Dan';
For cnt:= 1 to 4 do
begin
Writeln('Please enter the first name of the candidate and the number of votes');
readln(cndnme[cnt], votes[cnt]);
If votes[cnt] > highest then
begin
highest := votes[cnt];
winner := cndnme[cnt];
end;
end;
Writeln('The winner of this constituency is ', winner, ' with ', highest, ' votes');
readln;
end.
Result:
Please enter the first name of the candidate and the number of votes
Me
23
Please enter the first name of the candidate and the number of votes
You
42
Please enter the first name of the candidate and the number of votes
Ainun
18
Please enter the first name of the candidate and the number of votes
Jhon
38
The winner of this constituency is You with 42 votes

Why does my program not output all my data?

program ZZX1;
{$mode objfpc}{$H+}
uses
crt,
wincrt,
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
type
Masquerader = record
Name, CountyCode: string;
Payment: real;
end;
var
Applicant: array[1..10] of Masquerader;
DemList: array[1..10] of string;
BerList: array[1..10] of string;
EsqList: array[1..10] of string;
x:integer;
Y:integer;
DemCounter:integer;
BerCounter:integer;
EsqCounter:integer;
DemAmount:real;
BerAmount:real;
EsqAmount:real;
procedure LoadData;
begin
clrscr;
X:=0;
DemCounter:=0;
BerCounter:=0;
EsqCounter:=0;
DemAmount:=0;
BerAmount:=0;
EsqAmount:=0;
repeat
X:= x+1;
repeat
write('Enter Your County Code DemM or BerM or EsqM: ');
readln(Applicant[x].CountyCode);
until (Applicant[x].CountyCode= 'DemM') or (Applicant[x].CountyCode= 'BerM') or (Applicant[x].CountyCode= 'EsqM');
If Applicant[x].CountyCode = 'DemM' then
begin
write('Enter Your Name: ');
readln(Applicant[x].Name);
write('Enter Your Total Payment: ');
readln(Applicant[x].Payment);
clrscr;
DemCounter:= DemCounter + 1;
DemAmount:= DemAmount + Applicant[x].Payment;
DemList[DemCounter]:= Applicant[x].Name;
end;
If Applicant[x].CountyCode = 'BerM' then
begin
write('Enter Your Name: ');
readln(Applicant[x].Name);
write('Enter Your Total Payment: ');
readln(Applicant[x].Payment);
clrscr;
BerCounter:= BerCounter + 1;
BerAmount:= BerAmount + Applicant[x].Payment;
BerList[BerCounter]:= Applicant[x].Name;
end;
If Applicant[x].CountyCode = 'EsqM' then
begin
write('Enter Your Name: ');
readln(Applicant[x].Name);
write('Enter Your Total Payment: ');
readln(Applicant[x].Payment);
clrscr;
EsqCounter:= EsqCounter + 1;
EsqAmount:= EsqAmount + Applicant[x].Payment;
EsqList[EsqCounter]:= Applicant[x].Name;
end;
until x=6 ;
end;
Procedure PrintData;
begin
Y:= 0;
for y := 1 to 6 do
begin
writeln('Name: ', Applicant[y].Name);
writeln('CountyCode: ', Applicant[y].CountyCode);
writeln('Payment: ', Applicant[y].Payment:0:2);
writeln;
end;
For Y:= 1 to DemCounter do
begin
writeln(DemList[Y]);
writeln(DemCounter,'',' persons are registered in Demerara');
writeln;
writeln('DemTotal:$ ', DemAmount:0:2);
end;
For Y:= 1 to BerCounter do
begin
writeln(BerList[Y]);
writeln(BerCounter,'',' persons are registered in Berbice');
writeln;
writeln('BerTotal:$ ', BerAmount:0:2);
end;
For Y:= 1 to EsqCounter do
begin
writeln(EsqList[Y]);
writeln(EsqCounter,'',' persons are registered in Essequibo');
writeln;
writeln('EsqTotal:$ ', EsqAmount:0:2);
end;
end;
Procedure quit;
begin
writeln('Press <Enter> To Quit');
readln;
end;
begin
LoadData;
PrintData;
quit;
end.
This program currently collects 6 persons and groups them by their countycode, calculating the total amount of persons and money collected by each county.
When I run the program below my expected output is on the screen for a few seconds then it disappears leaving only a piece of the expected output( The end Part). Please assist.
If there are characters in the keyboard buffer when the program reaches the readln; statement in the procedure quit, readln will read those characters and continue onwards rather than waiting for further input before continuing.
To check this, try adding a character variable as a parameter to readln and write the ASCII value of the character out (or check its value in a debugger) to see if there is anything in that variable after the readln.
(EDIT)
After further thinking, I wonder if the code like:
For Y:= 1 to EsqCounter do
begin
writeln(EsqList[Y]);
writeln(EsqCounter,'',' persons are registered in Essequibo');
writeln;
writeln('EsqTotal:$ ', EsqAmount:0:2);
end;
... should actually read something like:
For Y:= 1 to EsqCounter do
begin
writeln(EsqList[Y]);
end;
writeln(EsqCounter,'',' persons are registered in Essequibo');
writeln;
writeln('EsqTotal:$ ', EsqAmount:0:2);
... because otherwise the same values of EsqCounter and EsqTotal will be output EsqCounter times, which seems unnecessary.

read() strings of variable length

I've got rows of two values (input from console) that look likes this:
David 89000
Peter 99500
Jim 23999
END 1
is there a way to save the string and number into a variable other than to loop-read a char when you don't know the string length?
str:=''; salary:=0; i:=1;
while str<> 'END' do
begin
str:=''; salary:=0;
read(ch);
while ch <> ' ' do
begin
str:=str+ch;
read(ch);
end;
read(salary);
array[i].name:=str;
array[i].salary:=salary;
i:=i+1;
readln;
end;
You can do it with a single call to ReadLn and then parse the input yourself:
var
TextIn: string;
Person: string;
Salary: Integer;
begin
while true do
begin
ReadLn(TextIn); // Requires user to hit Enter
if Copy(TextIn, 1, 3) <> 'END' then
begin
Person := Copy(TextIn, 1, Pos(' ', TextIn) - 1);
Salary := StrToInt(Copy(TextIn, Pos(' ', TextIn) + 1, 255);
end
else
Exit;
end;
end;
I didn't include any error checking (which should be there), because your original code doesn't have any either.
Not with standard I/O functions. Of course you can put that code in a separate procedure, or split with tstringlist.

Resources