Reputation: 1
uses crt;
var
i: integer;
stav: integer;
prsten: boolean;
begin
clrscr();
stav:=0;
prsten:=false;
repeat
case stav of
0: begin //Zacatek hry//
writeln('Toto je hra, jsi Princ a jsi v lese.');
writeln('Na krizovatce muzes jit doleva = 1, nebo doprava = 2');
readln(stav);
end;
1: begin
writeln('Potkas draka, ktery vezni krasnou princeznu. ');
writeln('3 = Prepadnout draka, 4 = Promluvit s nim');
readln(stav);
end;
2: begin
writeln('Potkas pocestneho. ');
writeln('5 = Pokracujes dal lesem, 6 = Promluvit s pocestnym');
readln(stav);
end;
3: begin
writeln('Drak je silnejsi nez Ty a tak te rozprasil na popel.');
writeln('Zacni znovu stisknutim klavesy 0.');
readln(stav);
end;
4: begin
writeln('Drak Te vyzve na souboj, ale Ty na nej nejsi jeste pripraven.');
writeln('Musis pokracovat dal lesem. Stiskni 5.');
readln(stav);
end;
5: begin
writeln('Po dlouhe a namahave ceste jsi dorazil do mistni knajpy.');
writeln('Najis a napijes se a pokracujes dal. Kousek od knajpy potkas pocestneho');
writeln('Promluvis s nim. Stiskni 6.');
readln(stav);
end;
6: begin
writeln('Povis mu, ze se pokousis zachranit princeznu pred drakem.');
writeln('On se ti rozhodne pomoci a daruje Ti kouzelny prsten.');
writeln('Nasadit prsten na ruku a pokracovat k drakovi 7 / Strcit prsten do kapsy 8 a pokracovat k drakovi.');
readln(stav);
end;
7: begin
writeln('Prijdes k drakovi a das se s nim do boje.');
writeln('Draka zabijes a muzes pokracovat k princezne.');
writeln('Pokracovat k princezne, stiskni 9.');
prsten:=true;
readln(stav);
end;
8: begin
writeln('Prijdes k drakovi a das se s nim do boje.');
writeln('Draka zabijes a muzes pokracovat k princezne.');
writeln('Pokracovat k princezne, stiskni 9.');
readln(stav);
prsten:=false;
end;
9: begin
if prsten then
writeln('Princeznu jsi uchvatil a muzes si ji odvest do hradu.');
else
wrtieln('Princezna je rada, ze jsi ji zachranil, ale opovrhuje Tebou.');
readln(stav);
end;
end;
until stav<0;
writeln('KONEC');
readln;
end.
What is causing the fatal error ";" expected but else founded
message?
Upvotes: 0
Views: 4928
Reputation: 125669
Let's take this opportunity to learn how to read and use error messages to your advantage.
The compiler tells you exactly what the error is (it's a ;
before an else
, because both of those are mentioned in the error message). It also gives you the exact line number where it's reporting the error; that's the number (usually in parentheses right before the error message, like (from Delphi):
[DCC Error] Project2.dpr(14): E2153 ';' not allowed before 'ELSE'
So the error is happening on line 14 (in my code - your number will be different). Let's look at that line and a few before and after:
if prsten then
writeln('Princeznu jsi uchvatil a muzes si ji odvest do hradu.');
else
wrtieln('Princezna je rada, ze jsi ji zachranil, ale opovrhuje Tebou.');
So look at the error message:
';' not allowed before 'ELSE'
That clearly tells you that the ;
in the line before the else
is the problem (that's very clear, because it says not allowed), so remove it.
BTW, now you're going to get another error:
[DCC Error] Project2.dpr(15): E2003 Undeclared identifier: 'wrtieln'
I think you should be able to figure that one out; again, the compiler gives you the exact line number.
You're going to get another one, if you've posted your entire code:
[DCC Error] Project2.dpr(18): E2029 Statement expected but end of file found
This is because you've left out the end.
that marks the end of a program file in Pascal. If you've not posted your entire code, you may not get it.
It's important to learn to actually read the words when you get an error message from the compiler. In most languages, the messages are clearly worded, and they all have information you can use to try to figure out (or at least narrow down) the problems in your code.
Upvotes: 2
Reputation: 21712
Unlike C, in Pascal a semicolon ;
separates statements, it does not terminate them, and the then
clause requires a single statement. then WriteLn(...); else
is two statements; you want then WriteLn(...) else
.
Upvotes: 4