-4

I want to test my pascal code but I can't figure out why it's getting this error:

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.
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
OOFERS
  • 1
  • 2
  • 1
    Images of code are absolutely useless. See [this Meta post](https://meta.stackoverflow.com/a/285557/62576) for a list of the many reasons why you should avoid posting images. Code and errors are in text, and should be posted as such. When you created your account here, it was suggested you take the [tour] and read the [help] pages in order to familiarize yourself with this site. Please do so, especially [ask] and [mcve], before posting your next question here. – Ken White Feb 28 '18 at 01:27
  • 1
    Thanks for the edit. If you learn to properly indent your code, and match `begin` and `end` statements, and learn that `end.` (end followed by a dot) indicates the end of the code, it will help you considerably. – Ken White Feb 28 '18 at 01:46
  • Also, in Pascal, there is *never* a semicolon right before the `else` for an `if`. Check your Pascal language manual. – lurker Feb 28 '18 at 01:51
  • Thank you so much i can't show how much appreciation i have for this – OOFERS Feb 28 '18 at 01:56
  • Hmmm... I have seen at least one very similar question, posted quite some time ago. Wasn't that answered? – Rudy Velthuis Feb 28 '18 at 11:23

1 Answers1

1

There are all kinds of problems with your code. If you properly indented it, the problems would be more apparent:

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.

The proper code should look more like this instead:

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.
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Oh my lord bless you kind sire i thank you for your time and i apologize that i couldn't indent the code properly but i'll be sure to read help centre pages – OOFERS Feb 28 '18 at 02:18
  • 1
    You could have indented the code properly. You just didn't. Note that proper formatting is not only important for the reader of the question, it is also important for you, as you will still be able to read it after, say 6 months, and it shows flaws in the logic and syntax, like wrong begin-end blocks, etc. Formatting is not luxury. – Rudy Velthuis Feb 28 '18 at 11:26