我该如何修复我的语法错误?
How can i fix my this syntax error?
我想测试我的 Pascal 代码,但我不知道为什么会出现此错误:
Fatal: Syntax error, ; expected but ELSE found
Program Lesson2_Program1;
Var
name, surname, community, inputAnswer : String;
GrossSalary, expenses, NetIncome: Integer;
Begin
write('Enter your name:');
readln(name);
writeln;{new line}
writeln;{new line}
writeln('Please proceed to enter your gross salary: ',name);
Begin {no semicolon}
Write('Input applicant GrossSalary:');
Readln(GrossSalary);
Writeln('Input applicant expenses:');
Readln(expenses);
NetIncome := GrossSalary - expenses; {subtraction};
Writeln(NetIncome);
writeln;{new line}
writeln('Please select a community (ClarendonC/SangreGV/ProvidenceG)');
readln(InputAnswer);
Begin
If (InputAnswer = 'ClarendonC') Then
If NetIncome>=12500 Then
Writeln('congragultions you qualify for this community');
Else
Writeln('Sorry, you do not qualify for the chosen community');
End.
Else if (InputAnswer = 'SangreGV') Then
If NetIncome>=9500 Then
If NetIncome<=12500 Then
Write('congragulations you qualify for this community');
Else
Write('Sorry, you do not qualify for the chosen community');
End.
你的代码有各种各样的问题。如果你适当地缩进它,问题会更明显:
Program Lesson2_Program1;
Var
name, surname, community, inputAnswer : String;
GrossSalary, expenses, NetIncome: Integer;
Begin
write('Enter your name:');
readln(name);
writeln;{new line}
writeln;{new line}
writeln('Please proceed to enter your gross salary: ',name);
Begin {no semicolon}
Write('Input applicant GrossSalary:');
Readln(GrossSalary);
Writeln('Input applicant expenses:');
Readln(expenses);
NetIncome := GrossSalary - expenses; {subtraction};
Writeln(NetIncome);
writeln;{new line}
writeln('Please select a community (ClarendonC/SangreGV/ProvidenceG)');
readln(InputAnswer);
Begin
If (InputAnswer = 'ClarendonC') Then
{ ERROR! Missing BEGIN }
If NetIncome>=12500 Then
Writeln('congragultions you qualify for this community'); { ERROR! Erroneous ';' }
Else
Writeln('Sorry, you do not qualify for the chosen community');
End. { ERROR! END without BEGIN, and Erroneous '.' }
Else if (InputAnswer = 'SangreGV') Then
{ WARNING! Missing BEGIN }
If NetIncome>=9500 Then
If NetIncome<=12500 Then
Write('congragulations you qualify for this community'); { ERROR! Erroneous ';' }
Else
Write('Sorry, you do not qualify for the chosen community');
{ WARNING! Missing ELSE ... END; for NetIncome < 9500 }
{ WARNING! Missing END; }
{ WARNING! Missing ELSE for 'ProvidenceG' }
{ ERROR! Missing END; }
{ ERROR! Missing END; }
End.
正确的代码应该看起来更像这样:
Program Lesson2_Program1;
Var
name, surname, community, inputAnswer : String;
GrossSalary, expenses, NetIncome: Integer;
Begin
Write('Enter your name: ');
Readln(name);
Writeln;{new line}
Writeln;{new line}
Writeln('Please proceed to enter your gross salary, ', name);
Write('Input applicant GrossSalary: ');
Readln(GrossSalary);
Writeln('Input applicant expenses: ');
Readln(expenses);
NetIncome := GrossSalary - expenses; {subtraction}
Writeln(NetIncome);
Writeln;{new line}
Writeln('Please select a community (ClarendonC/SangreGV/ProvidenceG)');
Readln(InputAnswer);
If (InputAnswer = 'ClarendonC') Then
Begin
If NetIncome >= 12500 Then
Writeln('Congratulations, you qualify for this community')
Else
Writeln('Sorry, you do not qualify for the this community');
End
Else if (InputAnswer = 'SangreGV') Then
Begin
If (NetIncome >= 9500) and (NetIncome <= 12500) Then
Write('Congratulations, you qualify for this community')
Else
Write('Sorry, you do not qualify for this community');
End
Else if (InputAnswer = 'ProvidenceG') Then
Begin
//...
End
Else
Write('Sorry, you entered an invalid community');
End;
End.
我想测试我的 Pascal 代码,但我不知道为什么会出现此错误:
Fatal: Syntax error, ; expected but ELSE found
Program Lesson2_Program1;
Var
name, surname, community, inputAnswer : String;
GrossSalary, expenses, NetIncome: Integer;
Begin
write('Enter your name:');
readln(name);
writeln;{new line}
writeln;{new line}
writeln('Please proceed to enter your gross salary: ',name);
Begin {no semicolon}
Write('Input applicant GrossSalary:');
Readln(GrossSalary);
Writeln('Input applicant expenses:');
Readln(expenses);
NetIncome := GrossSalary - expenses; {subtraction};
Writeln(NetIncome);
writeln;{new line}
writeln('Please select a community (ClarendonC/SangreGV/ProvidenceG)');
readln(InputAnswer);
Begin
If (InputAnswer = 'ClarendonC') Then
If NetIncome>=12500 Then
Writeln('congragultions you qualify for this community');
Else
Writeln('Sorry, you do not qualify for the chosen community');
End.
Else if (InputAnswer = 'SangreGV') Then
If NetIncome>=9500 Then
If NetIncome<=12500 Then
Write('congragulations you qualify for this community');
Else
Write('Sorry, you do not qualify for the chosen community');
End.
你的代码有各种各样的问题。如果你适当地缩进它,问题会更明显:
Program Lesson2_Program1;
Var
name, surname, community, inputAnswer : String;
GrossSalary, expenses, NetIncome: Integer;
Begin
write('Enter your name:');
readln(name);
writeln;{new line}
writeln;{new line}
writeln('Please proceed to enter your gross salary: ',name);
Begin {no semicolon}
Write('Input applicant GrossSalary:');
Readln(GrossSalary);
Writeln('Input applicant expenses:');
Readln(expenses);
NetIncome := GrossSalary - expenses; {subtraction};
Writeln(NetIncome);
writeln;{new line}
writeln('Please select a community (ClarendonC/SangreGV/ProvidenceG)');
readln(InputAnswer);
Begin
If (InputAnswer = 'ClarendonC') Then
{ ERROR! Missing BEGIN }
If NetIncome>=12500 Then
Writeln('congragultions you qualify for this community'); { ERROR! Erroneous ';' }
Else
Writeln('Sorry, you do not qualify for the chosen community');
End. { ERROR! END without BEGIN, and Erroneous '.' }
Else if (InputAnswer = 'SangreGV') Then
{ WARNING! Missing BEGIN }
If NetIncome>=9500 Then
If NetIncome<=12500 Then
Write('congragulations you qualify for this community'); { ERROR! Erroneous ';' }
Else
Write('Sorry, you do not qualify for the chosen community');
{ WARNING! Missing ELSE ... END; for NetIncome < 9500 }
{ WARNING! Missing END; }
{ WARNING! Missing ELSE for 'ProvidenceG' }
{ ERROR! Missing END; }
{ ERROR! Missing END; }
End.
正确的代码应该看起来更像这样:
Program Lesson2_Program1;
Var
name, surname, community, inputAnswer : String;
GrossSalary, expenses, NetIncome: Integer;
Begin
Write('Enter your name: ');
Readln(name);
Writeln;{new line}
Writeln;{new line}
Writeln('Please proceed to enter your gross salary, ', name);
Write('Input applicant GrossSalary: ');
Readln(GrossSalary);
Writeln('Input applicant expenses: ');
Readln(expenses);
NetIncome := GrossSalary - expenses; {subtraction}
Writeln(NetIncome);
Writeln;{new line}
Writeln('Please select a community (ClarendonC/SangreGV/ProvidenceG)');
Readln(InputAnswer);
If (InputAnswer = 'ClarendonC') Then
Begin
If NetIncome >= 12500 Then
Writeln('Congratulations, you qualify for this community')
Else
Writeln('Sorry, you do not qualify for the this community');
End
Else if (InputAnswer = 'SangreGV') Then
Begin
If (NetIncome >= 9500) and (NetIncome <= 12500) Then
Write('Congratulations, you qualify for this community')
Else
Write('Sorry, you do not qualify for this community');
End
Else if (InputAnswer = 'ProvidenceG') Then
Begin
//...
End
Else
Write('Sorry, you entered an invalid community');
End;
End.