Jump to content
Sign in to follow this  
VibeUK

Trudne poczatki Pascal :)

Recommended Posts

Witam,

Poczatki PASCAL'a, sporo rzeczy zrozumialem ale nie czaje skladni najwyrazniej.

Const
  psw='pupa';
Var
  wpis:string;

PROCEDURE Pytanie;
Begin
  ClrScr;
  Writeln('I-------------------------------------------I');
  Writeln('I          PODAJ HASLO           I');
  Writeln('I                                                I');
  Writeln('I                                                I');
  Writeln('I-------------------------------------------I');
  GotoXY(8,3);
  ReadLn(wpis)
End;

PROCEDURE Zle;
Begin
  ClrScr;
  Writeln('I-------------------------------------------I');
  Writeln('I              ZLE HASLO!!!          I');
  Writeln('I              ZLE HASLO!!!          I');
  Writeln('I              ZLE HASLO!!!          I');
  Writeln('I-------------------------------------------I');
End;

PROCEDURE Dobrze;
Begin
  ClrScr;
  Writeln('I-------------------------------------------I');
  Writeln('I                                                I');
  Writeln('I  HASLO PRAWIDLOWE!!!   I');
  Writeln('I                                                I');
  Writeln('I-------------------------------------------I');
End;

Begin
  REPEAT
  Pytanie;

  IF wpis=psw THEN
  Begin
    Dobrze;
  End;
  ELSE
  begin
    Zle;
  end;
  UNTIL wpis=psw;
 end.

Dlaczego ELSE nie moze byc uzyte jak w przykladzie wyzej? Jak wykonac procedure Zle jesli wpisane haslo=/=pupa?

Wiem, ze ten program mozna napisac inaczej ale chodzi mi wlasnie o uzycie ELSE.

Dzieki I sorry za (pewnie glupie) pytanie :)

Edited by VibeUK

Share this post


Link to post
Share on other sites

 IF wpis=psw THEN
  Begin
    Dobrze;
  End;
  ELSE
  begin
    Zle;
  end;
  

Nie powinno byc:
if wpis = psw then Dobrze else Zle;

?

 

ewentualnie 

 IF wpis=psw THEN
  Begin
    Dobrze;
  End // to nie koneic instrukcji wiec nie wstawiasz srednika
  ELSE
  begin
    Zle;
  end;

Edited by Małpożer

Share this post


Link to post
Share on other sites

Dokladnie, druga opcja jest ok, znalazlem 10 min temu w innym poradniku dla poczatkujacych.

Begin
  REPEAT
  Pytanie;

  IF wpis=psw THEN
  Begin
    Dobrze;
  End Else
  begin
    Zle;
  end;
  UNTIL wpis=psw;
 end.          

...kompiluje sie ok.

Dzieki wielkie. Tematu nie zamykam bo pewnie za 2h znow cos wyskoczy ;)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

Aktualności

Artykuły



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.