Jump to content

Dziwny bug w programie


Goodmorning

Recommended Posts

Witam. Piszę program, który wczytuje z pliku komendy i wykonuje je. Wszystko pięknie działa. Gdy jednak w pliku dwa razy użyję polecenia odwołującego się do read-u pojawia się problem. Program ignoruje drugie użycie tej opcji i leci dalej. Sprawdzałem kod tysiąc razy, mój brat (który też jest na tym forum) również sprawdził. I nic. Odkryliśmy tylko mały błąd w postaci braku średnika na końcu if-ów, ale to nie rozwiązało sprawy. Dam cały kod programu, ponieważ uważam że problem nie tkwi w samym if-ie który wykonuje procedurę read.

 

uses crt,dos;
var nazwa:string;
var tekstowka:text;
var polecenie:string;
var info:string;
var a:string;
var b:string;
var c:string;
var d:string;
var l:array[1..5] of integer;
var kod:integer;
begin

if ParamCount=1
then nazwa:=ParamStr(1);
assign(tekstowka,nazwa);
reset(tekstowka);

repeat

readln(tekstowka,polecenie);

if (polecenie='H') or (polecenie='h') or (polecenie='Helloworld!') or (polecenie='helloworld!') then write('Hello World!')

else if (polecenie='Napisz!') or (polecenie='napisz!') or (polecenie='Write!') or (polecenie='write!') then
    begin
    readln(tekstowka,info);
    if info='a' then write(a)
    else if info='b' then write(b)
    else if info='c' then write(c)
    else if info='d' then write(d)
    else write(info);
    end

else if (polecenie='Czekaj!') or (polecenie='czekaj!') or (polecenie='Wait!') or (polecenie='wait!') then
    begin
    readln(tekstowka,info);
    if info='a' then begin  val(a,l[1],kod); l[1]:=l[1] * 1000; delay(l[1]) end
    else if info='b' then begin val(b,l[2],kod); l[2]:=l[2] * 1000; delay(l[2]) end
    else if info='c' then begin val(c,l[3],kod); l[3]:=l[3] * 1000; delay(l[3]) end
    else if info='d' then begin val(b,l[4],kod); l[4]:=l[4] * 1000; delay(l[4]) end
    else begin val(info,l[5],kod); l[5]:=l[5] * 1000; delay(l[5]); end;
    end

else if (polecenie='Linia!') or (polecenie='linia!') or (polecenie='Enter!') or (polecenie='enter!') or (polecenie='Line!') or (polecenie='line!') then writeln

else if (polecenie='zapytaj!') or (polecenie='Zapytaj!') or (polecenie='Ask!') or (polecenie='ask!') then
begin
    readln(tekstowka,info);
    if info='a' then read(a)
    else if info='b' then read(b)
    else if info='c' then read(c)
    else if info='d' then read(d);
end

else if (polecenie='Pauza!') or (polecenie='pauza!') or (polecenie='Stop!') or (polecenie='stop!') or (polecenie='Pause!') or (polecenie='pause!') then readkey

else if polecenie='a' then
begin
readln(tekstowka, info);
a:=info;
end

else if polecenie='b' then
begin
readln(tekstowka, info);
b:=info;
end

else if polecenie='c' then
begin
readln(tekstowka, info);
c:=info;
end

else if polecenie='d' then
begin
readln(tekstowka, info);
d:=info;
end

else if (polecenie='czysc!') or (polecenie='Czysc!') or (polecenie='Clear!') or (polecenie='clear!') then clrscr;


until(polecenie='');
writeln;
writeln;
write('Koniec programu');
readkey;
end.

Link to comment
Share on other sites

KOD

napisz!

Pierwsze slowo:

zapytaj!

a

linia!

napisz!

Drugie slowo:

zapytaj!

b

Czysc!

napisz!

a

linia!

napisz!

b

 

Program od razu powtarza słowo, czyli nie bierze pod uwagę linijek od 3 do 9.

 

EDIT

 

Zapomniałem, że jest tam instrukcja "Czysc!" To dlatego nie pokazuje napisu "Drugie slowo".

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...