-2

It gives an error at the first else, saying it was not expected

Also if some one is willing to add me in Skype so I can ask these basic questions, it would help a lot.

Program Game ;

var answer: string;

Begin

writeln('(======= MENU =======)');
writeln('-------- PLAY --------');  
writeln('-------- HELP --------');
writeln('-------- EXIT --------');

repeat

writeln('Pick PLAY, HELP or EXIT');
readln(answer);

if answer = 'EXIT' then
      writeln();
      writeln('Write EXIT again!')
    else 
      if answer = 'HELP' then
    writeln();
    writeln('Simple commands like observe, look, take.')
      else 
    if answer = 'PLAY' then
    writeln();
            writeln('You are in a cave!');

until answer = 'EXIT';

End.
crashmstr
  • 28,043
  • 9
  • 61
  • 79
Scar
  • 43
  • 8

1 Answers1

0

Pascal expects one statement between if and else. It understands your code incorrectly:

if answer = 'EXIT' then
    writeln(); (* one statement *)

writeln('Write EXIT again!') (* unrelated to the "if" above *)

else (* error - no preceding "if" *)

The solution is, use begin and end to enclose 2 statements in one:

if answer = 'EXIT' then
  begin
    writeln();
    writeln('Write EXIT again!')
  end
else
...
anatolyg
  • 26,506
  • 9
  • 60
  • 134