Что я получаю Ошибка: идентификатор не найден "pari sh" source.pas (7,9) Неустранимый: синтаксическая ошибка, ";" ожидается, но ":" найден? - PullRequest
0 голосов
/ 22 марта 2020
BEGIN
(*Declaration of variables*)

Каждый раз, когда я запускаю свою программу, я получаю ту же ошибку, что что-то не так с синтаксисом в этом разделе

 parish : String; (*Error: identifier not found "parish"*)
 pat_mny, sa_mny, sm_mny, se_mny, sj_mny, p_mny, st_mny : Real; (*Fatal: Syntax error, ";" expected but ":" found*)
 j, sa, sm, se, sj, p, st, max : Integer;

Эта программа вычисляет общее количество пациентов, которые посетили каждый пари sh и отображает максимальную пари sh стоимость

Print ('*****Ministry of Health Database File*****');
Print ('Hello, this is the Dengue Eradication Task Force Computing Program, please make sure to follow the instructions given else there will be a compile error ');
Print('ALL parishes entered MUST BE spelt correctly. Any parish from the parish list may be entered (EXCEPTIONS WILL PRODUCE A COMPILE ERROR).')
Print ('PARISH LIST: St. Ann, St. Mary, St. Thomas, St. Elizabeth, St. James and Portland');




     (*Loop to ensure that the program repeats this block of code 10 times*)
        (*Prompting the user for input*)
    for j :=1-10 do 
        begin
          Write ('Enter the name of the parish the patient visited: ');
        Readln (parish);
        Write ('Enter the amount that the patient paid:');
        Readln (pat_mny);

        (*Processing to compute the number of patients and the total cost for each parish*)
        while (parish := "St. Ann") do

            begin
            sa := 1+0;
            sa_mny := sa_mny+  pat_mny;
            end;

        while (parish := "St. Mary") do 

            begin
            sm:=1+0;
            sm_mny := sm_mny+pat_mny;
            end;

        while (parish := "St. Elizabeth") do

            begin
            se :=1+0;
            se_mny := se_mny+pat_mny;
            end;

        while (parish := "St. Thomas") do

            begin
            st := 1+0;
            st_mny := st_mny+pat_mny;
            end;

        while (parish := "St. James") do

            begin
            sj :=1+0;
            sj_mny := sj_mny+pat_mny;
            end;

        while (parish := "Portland") do

            begin
            p:=1+0;
            p_mny :=p_mny+pat_mny;
            end;

    end;

    (*Processing to compute the maximum cost*)
    max :=0;
    if ( sa<sm) then

        begin
         max:=sm;
        end;

    else if (sm<se) then

        begin
         max:=se; 
        end;

    else if (se<st) then

        begin
         max:=st;
        end;

    else if (st<sj) then

        begin
         max:=sj:
        end;

    else

        begin
         max:=p;
        end;

    end;

    (*Prompting the computer output*)

    Writeln ('St. Ann: Total cost $', sa_mny 'No. of Patients', sa)
    Writeln ('St. Mary: Total cost $', sm_mny 'No. of Patients', sm)
    Writeln ('St. Elizabeth: Total cost $', se_mny 'No. of Patients', se)
    Writeln ('St. Thomas: Total cost $', st_mny `enter code here`'No. of Patients', st)
    Writeln ('St. James: Total cost $', sj_mny 'No. of Patients', sj)
    Writeln ('Portland: Total cost $', p_mny 'No. of Patients', p)
    Writeln ('The maximum total cost is $', max)
    Print ('Thank you for using the DETF Computing Program. Good day!')
    END.

1 Ответ

0 голосов
/ 23 марта 2020

Это исправление к приведенному выше коду ... Спасибо всем, кто нашел время, чтобы прокомментировать мой вопрос, чтобы помочь мне. Спасибо за ваше внимание.

В разделе, где у меня есть Var, сначала у меня было Begin, а затем я объявил переменные без использования ключевого слова var. Я изменил код, чтобы исправить синтаксическую ошибку, удалив объявление переменных вне блока кода в разделах begin и end. Также изменил max на real тип данных, потому что я хотел, чтобы он хранил число с плавающей запятой.

Program DETFComputingProgram;
Var
(*Declaration of variables*)

 parish : String; 
 pat_mny, sa_mny, sm_mny, se_mny, sj_mny, p_mny, st_mny, max: Real;
 j, sa, sm, se, sj, p, st : Integer;

Ранее я не инициализировал свои переменные. Я инициализирую свои переменные в главном разделе begin и end.

Begin
 sa_mny:=0; sm_mny:=0; se_mny:=0; sj_mny:=0; p_mny:=0; st_mny:=0 ;
  sa:=0; sm:=0; se:=0; sj:=0; p:=0; st:=0 ;

В этом разделе кода ниже, где у меня есть Writeln, у меня было Print, что также вызвало ошибку.

Writeln('*****Ministry of Health Database File*****');
Writeln ('Hello, this is the Dengue Eradication Task Force Computing Program, please make sure to follow the instructions given else there will be a compile error ');
Writeln('ALL parishes entered MUST BE spelt correctly. Any parish from the parish list may be entered (EXCEPTIONS WILL PRODUCE A COMPILE ERROR).');
Writeln('PARISH LIST: St. Ann, St. Mary, St. Thomas, St. Elizabeth, St. James and Portland');

(*Loop to ensure that the program repeats this block of code 10 times*)
(*Prompting the user for input*)

Ранее у меня было for j:=1-10 do, что также дает синтаксическую ошибку, правильный синтаксис - for j :=1 to 10 do. Также я добавил точку с запятой в конце одной из этих строк в разделе кода ниже, где она отсутствовала.

for j:=1 to 10 do 
begin
  Writeln('Enter the name of the parish the patient visited: ');
Readln (parish);
Writeln('Enter the amount that the patient paid:');
Readln (pat_mny);

В этом разделе кода ниже я использовал while l oop вместо конструкции if()then. У меня было while (parish := "St.Ann") do. Здесь я узнал, что это был недопустимый код (спасибо), и я предложил использовать конструкцию if()then, чтобы код выглядел следующим образом if(parish = 'St.Ann') then.

(*Processing to compute the number of patients and the total cost for each parish*)
if (parish ='St. Ann') then
begin
sa := sa+1;
sa_mny := sa_mny+  pat_mny;
end;
if (parish ='St. Mary') then
begin
sm:=sm+1;
sm_mny := sm_mny+pat_mny;
end;
if (parish ='St. Elizabeth')then
begin
se :=se+1;
se_mny := se_mny+pat_mny;
end;
if  (parish = 'St. Thomas') then
begin
st := st+1;
st_mny := st_mny+pat_mny;
end;
if (parish = 'St. James')then
begin
sj :=sj+1;
sj_mny := sj_mny+pat_mny;
end;
if (parish = 'Portland') then
begin
p:=p+1;
p_mny :=p_mny+pat_mny;
end;
end;

В этом разделе кода ниже я поставил точки с запятой в конце каждого оператора условия max:=sm_mny;. Точки с запятой должны go только в конце операторов, следующих после else в конструкции if()then. Также я сделал несколько ошибок логики c, поэтому я исправил их, чтобы получить правильные вычисления.

(*Processing to compute the maximum cost*)
max :=0;
if ( sa_mny<sm_mny) then
 max:=sm_mny
else 
if (sm_mny<se_mny) then
 max:=se_mny 

else 
if (se_mny<st_mny) then
 max:=st_mny

else 
    if (st_mny<sj_mny) then
     max:=sj_mny
else
 max:=p_mny;
end.

( Запрос на вывод компьютера )

Writeln ('St. Ann: Total cost $', sa_mny 'No. of Patients', sa)
Writeln ('St. Mary: Total cost $', sm_mny 'No. of Patients', sm)
Writeln ('St. Elizabeth: Total cost $', se_mny 'No. of Patients', se)
Writeln ('St. Thomas: Total cost $', st_mny 'No. of Patients', st)
Writeln ('St. James: Total cost $', sj_mny 'No. of Patients', sj)
Writeln ('Portland: Total cost $', p_mny 'No. of Patients', p)
Writeln ('The maximum total cost is $', max)
Writeln('Thank you for using the DETF Computing Program. Good day!')
End.
...