Fatal syntax error then expected but found

Почему выдаёт ошибку? Где я накосячила? Ошибка: unit1.pas(120,5) Fatal: Syntax error, «;» expected but «ELSE» found procedure TForm1.RadioButton1Change(Sender: TObject); begin if radiobutton1.checked then begin edit1.text := IntToStr(Bin2Dec(edit1.text)); CS := 10; s:=edit1.text end; else begin edit1.text := IntToStr(Oct2Dec(edit1.text)); CS := 10; s:=edit1.text; Button1.Enabled:=True; Button2.Enabled:=True; Button3.Enabled:=True; Button4.Enabled:=True; Button5.Enabled:=True; Button6.Enabled:=True; Button7.Enabled:=True; Button8.Enabled:=True; Button9.Enabled:=True; Button10.Enabled:=True; Button11.Enabled:=True; Button12.Enabled:=True; Button13.Enabled:=True; […]

Содержание

  1. Почему выдаёт ошибку? Где я накосячила? Ошибка: unit1.pas(120,5) Fatal: Syntax error, «;» expected but «ELSE» found
  2. Fatal: Syntax error, «.» expected but «;» found
  3. 1 Answer 1
  4. Pascal Help ? 6 errors that I do not know how to fix
  5. TacticalMaestro
  6. [Паскалъ] Need Help
  7. Why does syntax error appear after running code?
  8. 1 Answer 1

Почему выдаёт ошибку? Где я накосячила? Ошибка: unit1.pas(120,5) Fatal: Syntax error, «;» expected but «ELSE» found

procedure TForm1.RadioButton1Change(Sender: TObject);
begin
if radiobutton1.checked then
begin
edit1.text := IntToStr(Bin2Dec(edit1.text));
CS := 10;
s:=edit1.text
end;
else begin
edit1.text := IntToStr(Oct2Dec(edit1.text));
CS := 10;
s:=edit1.text;

Button1.Enabled:=True;
Button2.Enabled:=True;
Button3.Enabled:=True;
Button4.Enabled:=True;
Button5.Enabled:=True;
Button6.Enabled:=True;
Button7.Enabled:=True;
Button8.Enabled:=True;
Button9.Enabled:=True;
Button10.Enabled:=True;
Button11.Enabled:=True;
Button12.Enabled:=True;
Button13.Enabled:=True;
Button15.Enabled:=True;
Button16.Enabled:=True;
Button17.Enabled:=True;
Button18.Enabled:=True;
Button14.Enabled:=True;
Button19.Enabled:=True;
Button20.Enabled:=True;
Button21.Enabled:=True;
Button22.Enabled:=True;
Button23.Enabled:=True;
end;

—-исходный кусок ————
CS := 10;
s:=edit1.text
end;
else begin
————неправильно, д. б. так ——————-
CS := 10;
s:=edit1.text;
end
else begin

З. Ы. внимательнее с синтаксисом. лучше код форматировать отступами, вроде так:
begin
begin
.
end;
end;
сразу ясно какой энд какому бегину принадлежит )))

Источник

Fatal: Syntax error, «.» expected but «;» found

1 Answer 1

The reason for this is that your begin s and end s are not balanced; disregarding the opening begin and closing end. for the program’s syntax to be correct, you should have equal numbers of each, but you have 4 begin s and 8 end s.

Obviously, your code is to compute the solutions of a quadratic equation. What I think you should do is to adjust the layout of your code so that it reflects that and then correctly the begin s and end s. In particular, your program is trying to detect whether any of a, b and d is zero and, if so, write a diagnostic message, otherwise calculate the roots by the usual formula.

Unfortunately, your begin s and end s do not reflect that. Either the whole of the block starting d := . needs to be executed or none of it does, so the else on the line before needs to be followed by a begin , as in

(You don’t say which Pascal compiler you are using, but the above fixes two points which are flagged as errors in FreePascal.

If you need more help than that, please ask in a comment.

Btw, there are some grammatical constructs in Pascal implementations where an end can appear without a matching preceding begin such as case . of . end .

Источник

Pascal Help ? 6 errors that I do not know how to fix

TacticalMaestro

Estimable

Program TypeofCreditCard;
Var
AppliName: array[1..99] of String;
SSnum: array[1..99] of Integer;
GSal: array[1..99] of Integer;
TSalD: array[1..99] of Integer;

Name, CC : String;
Rep,Exp, GS,NS,Sum,TSD , YS,SSN,i,C_Amt,PofIncome : integer ;

Begin
Writeln ( ‘Enter applicants who applied for a type of credit card’);
Readln (Rep,Exp,GS,YS,NS,Sum,TSD,SSN,CC,PofInco. ;

While ( Name <> ‘ Stop ‘ ) do
Begin
NS:= GS-TSD ;
Sum:= Exp + Rep ;
PofIncome:=(NS * 0.45);
Begin
If ( GS >4000) AND ( CC = ‘Bronze Card’ ) then
YS:= GS * 12 ;
C_Amt := YS * 0.25;
i:= i + 1;
AppliName := Name;
SSNum := SSN ;
GSal [ i]:= GS ;
TSalD := TSD ;
End ;
Begin
If (GS >= 7500) AND [CC= ‘Gold Card’] then
YS:= GS * 12 ;
C_Amt:= YS * 0.3;
i:= i + 1 ;
AppliName := Name;
SSnum:=SSN;
GSal:=GS;
TSalD:=TSD;
End;
Begin
If (GS>=10,000) AND ( CC = ‘ Platinum Card’) then
YS := GS * 12;
C_Amt: = YS * 0.4;
i:= i + 1;
A ppliName := Name;
SSNum := SSN;
GSal :=GS;
TSalD := TSD;

End if
End if
End if
End While
End.

The five errors are :
1. Error:Incompatible types: got «Boolean» expected «LongInt» — For this line : If (GS >= 7500) AND [CC= ‘Gold Card’] then

2.Error:Incompatible types: got » Set of Boolean» expected » LongInt» — for the same line (If (GS >= 7500) AND [CC= ‘Gold Card’] then )

3.Error:Incompatible types: got «single» expected «smallint» — for C_Amt := YS * 0.25 ; in Bronze Card

4.Error:Incompatible types: got «extended» expected «smallint» for C_Amt := YS * 0.3; in Gold Card

5.Fatal:syntax error , «)» expected but «,» found — (If GS >= 10000) AND [CC= ‘Platinum’] then )

Thanks for any help. I know my program is by no means perfect because I am awful at Pascal and desperately need help on fixing these things. So I am open to anything that will get this program running in Pascal. Thanks.

Источник

[Паскалъ] Need Help

Что программа должна делать(на пхп)

ЕМНИП перед else там точка с запятой не ставится.

Не, ругается на другое, и спасибо это пофиксил.

> перед else там точка с запятой не ставится.

> ругается на другое

Условия в скобки попробуй.

Перед else ; не ставится.

У readln точно такой синтаксис? (я уже запамятовал)

Условия в скобки не надо?

Операции сравнения в скобки возьми.

А теперь, дружище, запомни, что вот этот выхлоп

untitled.pas(26,7) Error: Incompatible types: got «Boolean» expected «LongInt»
untitled.pas(28,2) Fatal: Syntax error, «;» expected but «ELSE» found

должен читать ТЫ сам, а не ЛОР.

Свободно говорю на Русском, Литовском, Английском.

Свободно говорю на Английском

Error: Incompatible types: got «Boolean» expected «LongInt»

Fatal: Syntax error, «;» expected but «ELSE» found

Источник

Why does syntax error appear after running code?

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.

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.

1 Answer 1

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).

Источник

Shadan10

0 / 0 / 0

Регистрация: 01.10.2021

Сообщений: 5

1

01.10.2021, 20:08. Показов 1605. Ответов 8

Метки error, lazarus, pyton, syntax (Все метки)


Помогите исправить ошибку. Я прикреплю код и фото программ. Вскакивает ошибка в 50 строке, перед then. Если оставляю одно условие, то потом пишет что проблема в последнем End, тоже не понимаю почему???? Помогите плиз!

Pascal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
procedure TForm1.Button1Click(Sender: TObject);
var x, y, c: real;
begin
x:= StrToInt (Edit1.Text);
y:= StrToInt (Edit2.Text);
//c:= StrToInt (Edit3.Text);
 if
 RadioButton1.Checked and ((Sqr(x)+Sqr(y)<=1) and ((Sqr(x)-2+Sqr(y))<=4) and (x<=1) and (x>=0)
or RadioButton2.Checked and ((Sqr(x)+Sqr(y)<1) and ((Sqr(x)-2+Sqr(y))<4) and (x<1) and (x>0) then
  begin
  Edit3.Clear;
  Edit3.Text := 'Точка пренадлежит области'
  end
 else
  begin
  Edit3.Clear;
  Edit3.Text := 'Точка не пренадлежит области'
  end;
 
end.

Миниатюры

Fatal: Syntax error, ")" expected but "THEN" found
 

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



Programming

Эксперт

94731 / 64177 / 26122

Регистрация: 12.04.2006

Сообщений: 116,782

01.10.2021, 20:08

Ответы с готовыми решениями:

Ошибка «project1.lpr(35,0) Fatal: Syntax error, «BEGIN» expected but «end of file» found»
type
tarray= array of integer;
var
a:tarray;
m,s,k:integer;
procedure…

Компилятор выдает ошибку «Fatal: Syntax error, «;» expected but «ELSE» found»
var
Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure…

Ошибка «Fatal: Syntax error, «;» expected but «.» found»
звучит задание: создай программу, в которой можно преподнести введенное пользователем число к…

Пишет source.pas(6,94) Fatal: Syntax error, «)» expected but «,» found Error: /usr/bin/ppcx
uses crt;
const a:array of string=(‘Хорошо’,’Плохо’);
const b:array of string=(‘Что-нибудь…

Ошибка unit1.pas(48,0) Fatal: Syntax error, «BEGIN» expected but «end of file» found
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils, Forms, Controls,…

8

пофигист широкого профиля

4602 / 3062 / 850

Регистрация: 15.07.2013

Сообщений: 17,669

01.10.2021, 20:45

2

Считай скобки.



0



Puporev

Почетный модератор

64272 / 47571 / 32739

Регистрация: 18.05.2008

Сообщений: 115,182

01.10.2021, 20:56

3

Лучший ответ Сообщение было отмечено Shadan10 как решение

Решение

Так попробуй

Delphi
1
2
if (RadioButton1.Checked and (Sqr(x)+Sqr(y)<=1) and (Sqr(x)-2+Sqr(y)<=4) and (x<=1) and (x>=0))
or (RadioButton2.Checked and (Sqr(x)+Sqr(y)<1) and (Sqr(x)-2+Sqr(y)<4) and (x<1) and (x>0)) then



1



0 / 0 / 0

Регистрация: 01.10.2021

Сообщений: 5

01.10.2021, 21:11

 [ТС]

4

Все получилось!!!! Спасибо, теперь ошибка в последнем end пишет unit1.pas(60,4) Fatal: Syntax error, «;» expected but «.» found.
А что была за ошибка, расскажи чтобы я понял, а не тупо переписал, и помоги с последним end



0



Почетный модератор

64272 / 47571 / 32739

Регистрация: 18.05.2008

Сообщений: 115,182

01.10.2021, 21:13

5

Перед последним end. нужно написать end;(конец процедуры).

Цитата
Сообщение от Shadan10
Посмотреть сообщение

А что была за ошибка

Неправильно расставленные скобки.



1



0 / 0 / 0

Регистрация: 01.10.2021

Сообщений: 5

01.10.2021, 21:15

 [ТС]

6

Понял, как надо было, а как в последнем исправить?



0



Почетный модератор

64272 / 47571 / 32739

Регистрация: 18.05.2008

Сообщений: 115,182

01.10.2021, 21:16

7

Лучший ответ Сообщение было отмечено Shadan10 как решение

Решение

Я же написал

Цитата
Сообщение от Puporev
Посмотреть сообщение

Перед последним end. нужно написать end;(конец процедуры).



0



0 / 0 / 0

Регистрация: 01.10.2021

Сообщений: 5

01.10.2021, 21:18

 [ТС]

8

Получилось все!!! Спасибо! Что сделать, типо чтобы тебе плюс был?



0



Почетный модератор

64272 / 47571 / 32739

Регистрация: 18.05.2008

Сообщений: 115,182

01.10.2021, 21:25

9

Нажми кнопку Спасибо.



2



IT_Exp

Эксперт

87844 / 49110 / 22898

Регистрация: 17.06.2006

Сообщений: 92,604

01.10.2021, 21:25

Помогаю со студенческими работами здесь

Ошибка: project1.lpr(1,1) Fatal: Syntax error, «BEGIN» expected but «end of file» found
project1.lpr(1,1) Fatal: Syntax error, &quot;BEGIN&quot; expected but &quot;end of file&quot; found
выдает эту ошибку…

fatal:syntax error, «:» expected but «;» found как исправить, подскажите пожалуйста
на скрине ошибка. как её исправить, подскажите пож. работаю в этой программе 2 раз только

Ошибка: Fatal: Syntax error, «;» expected but «identifier Mas» found.
Где здесь синтаксическая ошибка( &quot;mas:=A2;&quot; )?

procedure TForm1.Button1Click(Sender: TObject);

Ошибка unit1.pas(89,4) Fatal: Syntax error, «;» expected but «.» found
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,…

Fatal: Syntax error, «BEGIN» expected but «identifier BITMAP» found
Добрый день! пишу программу по методичке, выдает вот такие ошибки:
unit1.pas(78,1) Fatal: Syntax…

Ошибка u_test.pas(63,62) Fatal: Syntax error, «THEN» expected but «;» found
Ошибка в строчке
if RadioGroup1.Items.Add(‘Нулевой меридиан’);
RadioGroup должен выбирать…

Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:

9

Topic: problem with Fatal: Syntax error, «;» expected but «:» found  (Read 5274 times)

Hello, I am a beginner in Lazarus and the Pascal language.
my problem is that every time I try to run my program it gives me this error: Fatal: syntax error, «;» expected but found.
in case there is any doubt this is the program.
program division;
var
a,b,c:double;
begin
writeln(‘extra division’);
writeln(‘ingresa el divisor’);
readln(a);
writeln(‘ingresa el dividendo’);
readln(b);
if (b=0) then
begin
writeln(‘math error’);
readln;
end
else
begin
c:a/b;
writeln(‘el resultado de la division es’,c:4:2);
readln;
end;

I would be very grateful to you if you could help me solve this problem.


Logged



Logged


HOMEWORK ???

  1. PROGRAM Division;

  2. VAR dDividend,dDivisor,dQuotient:Double;

  3. BEGIN

  4. Writeln(‘extra division’);

  5. Writeln(‘ingresa el dividendo’);

  6. Readln(dDividend);

  7. Writeln(‘ingresa el divisor’);

  8. Readln(dDivisor);

  9. If (dDivisor = 0)

  10. Then

  11. Begin

  12. Writeln(‘math error’);

  13. Readln;

  14. End

  15. Else

  16. Begin

  17.     dQuotient:= dDividend/dDivisor;

  18. Writeln(‘el resultado de la division es:  ‘,dQuotient:4:2);

  19. Readln;

  20. END;

  21. END.


Logged

Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).



Logged


Hello, I am a beginner in Lazarus and the Pascal language.
my problem is that every time I try to run my program it gives me this error: Fatal: syntax error, «;» expected but found.
in case there is any doubt this is the program.
program division;
var
a,b,c:double;
begin
writeln(‘extra division’);
writeln(‘ingresa el divisor’);
readln(a);
writeln(‘ingresa el dividendo’);
readln(b);
if (b=0) then
begin
writeln(‘math error’);
readln;
end
else
begin
c:a/b;
writeln(‘el resultado de la division es’,c:4:2);
readln;
end;

I would be very grateful to you if you could help me solve this problem.


Logged

One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
———————————————————————
Code is like a joke: If you have to explain it, it’s bad


This line:

  1. c:a/b;

Needs to be changed to this:

  1. c := a/b;

Also, you need to add the following at the bottom of the file to close your 1st ‘begin’ and the unit as a whole:

  1. end.

So, the entire code should look like this:

  1. program division;

  2. var

  3.   a, b, c : double;

  4. begin

  5. WriteLn(‘extra division’);

  6. WriteLn(‘ingresa el divisor’);

  7. ReadLn(a);

  8. WriteLn(‘ingresa el dividendo’);

  9. ReadLn(b);

  10. if (b=0) then

  11. begin

  12. WriteLn(‘math error’);

  13. ReadLn;

  14. end

  15. else

  16. begin

  17.     c := a / b; // <— CHANGED!!!

  18. WriteLn(‘el resultado de la division es’, c:4:2);

  19. ReadLn;

  20. end;

  21. end. // <— ADDED!!!

« Last Edit: June 19, 2020, 08:31:39 pm by Remy Lebeau »


Logged


@Remy Lebeau: almost … one is missing …  :P
You don’t get the flower pot !


Logged

Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).


@Remy Lebeau: almost … one is missing …  :P

Which one?  I don’t see anything missing in the code I posted.


Logged


I don’t see anything missing in the code I posted.

Correct, nothing is missing, but the «WriteLn» order is not optimal…

Divisor (a), Dividend (b), Check b = 0 (Dividend?), Divisor/Dividend ?

In my world you have to do it like this:
Dividend / Divisor = Quotient   :)

As I said, you don’t get the flower pot …  :D


Logged

Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).


Hi!

Dont battle about the poor dividende.

We could teach him the way the C boys do it:
Division by zero is no error. Never.

SetExceptionMask([exZeroDivide, exInvalidOp, exDenormalized, exOverflow, exUnderflow, exPrecision]);
….

You dont have to ask for dividing by zero anymore.
The price you have to pay:
Incorrect results and a system crash every now and then.
We all know that from Windows.

Winni


Logged


Dont battle about the poor dividende.

We could teach him the way the C boys do it:
Division by zero is no error. Never.

I think RAW is referring just to the terminology in the WriteLn’s: Remy’s code asks for the divisor when he means the dividend and viceversa. Just a small oversight ;D


Logged

Turbo Pascal 3 CP/M — Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 — 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.


…code asks for the divisor when he means the dividend and viceversa…

@lucamar: the flowers are all yours …  :)

by the way: no battle at all, just a little hint that the code isn’t optimal …  :)


Logged

Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).


I think RAW is referring just to the terminology in the WriteLn’s: Remy’s code asks for the divisor when he means the dividend and viceversa. Just a small oversight ;D

It is not MY code, it is the OP’s code.  I just fixed the syntax errors, not the logic errors.


Logged


Понравилась статья? Поделить с друзьями:

Читайте также:

  • Fatal syntax error expected but var found
  • Fatal syntax error expected but uses found
  • Fatal syntax error expected but procedure found
  • Fatal syntax error expected but identifier writeln found
  • Fatal syntax error expected but identifier write found

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии