Delphi-PRAXiS
Seite 3 von 4     123 4      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Lotto programm (https://www.delphipraxis.net/105237-lotto-programm.html)

ScrollbarKopf 18. Dez 2007 15:58

Re: Lotto programm
 
sol cih einfach richtig : boolean dann
if StrToInt( edit1.text) = StrToInt( edit7.text) then richtig:= true ;

Progman 18. Dez 2007 15:59

Re: Lotto programm
 
genau so.

ScrollbarKopf 18. Dez 2007 16:02

Re: Lotto programm
 
aber jetzt steht sie haben gewoonen auch da wenn die zahlen nicht gleich sind

ScrollbarKopf 18. Dez 2007 16:02

Re: Lotto programm
 
Hier nochmal der ganze code bis jetzt
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    Edit12: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c,d,e,f :integer;
richtig: boolean;
falsch: boolean;

begin
randomize;
repeat
  a:= random (46);
  b:= random (46);
  c:= random (46);
  d:= random (46);
  e:= random (46);
  f:= random (46);

until (a<>b) and (a<>c) and (a<>d) and (a<>e) and (a<>f)
and  (b<>a) and (b<>c) and (b<>d) and (b<>e) and (b<>f)
and  (c<>a) and (c<>b) and (c<>d) and (c<>d) and (c<>f)
and  (d<>a) and (d<>b) and (d<>c) and (d<>e) and (d<>f)
and  (e<>a) and (e<>b) and (e<>c) and (e<>d) and (e<>f)
and  (f<>a) and (f<>b) and (f<>c) and (f<>d) and (f<>e);

edit1.Text := inttostr (a+1);
edit2.Text := inttostr (b+1);
edit3.Text := inttostr (c+1);
edit4.Text := inttostr (d+1);
edit5.Text := inttostr (e+1);
edit6.Text := inttostr (f+1);

if StrToInt( edit1.text) = StrToInt( edit7.text) then richtig := true ;
if StrToInt( Edit2.text) = StrToInt( Edit8.text) then richtig := true ;
if StrToInt( Edit3.text) = StrToInt( Edit9.text) then richtig := true ;
if StrToInt( Edit4.text) = StrToInt( Edit10.text) then richtig := true ;
if StrToInt( Edit5.text) = StrToInt( Edit11.text) then richtig := true ;
if StrToInt( Edit6.text) = StrToInt( Edit12.text) then richtig := true ;

if true then showmessage ('Sie haben Gewonnen');

if StrToInt( Edit1.text) <> StrToInt( Edit7.text) then falsch := false ;
if StrToInt( Edit2.text) <> StrToInt( Edit8.text) then falsch := false ;
if StrToInt( Edit3.text) <> StrToInt( Edit9.text) then falsch := false ;
if StrToInt( Edit4.text) <> StrToInt( Edit10.text) then falsch := false ;
if StrToInt( Edit5.text) <> StrToInt( Edit11.text) then falsch := false ;
if StrToInt( Edit6.text) <> StrToInt( Edit12.text) then falsch := false ;

if false then showmessage ('Sie haben leider verloren');

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
edit1.clear;
edit2.clear;
edit3.clear;
edit4.clear;
edit5.clear;
edit6.clear;
edit7.clear;
edit8.clear;
edit9.clear;
edit10.clear;
edit11.clear;
edit12.clear;
end;

end.

DeddyH 18. Dez 2007 16:04

Re: Lotto programm
 
Nicht if true bzw. if false, sondern if richtig/if falsch

Progman 18. Dez 2007 16:04

Re: Lotto programm
 
Delphi-Quellcode:
if StrToInt( Edit1.text) <> StrToInt( Edit7.text) then falsch := TRUE;
Wenn die Variable "falsch" wahr sein soll, muss sie auf True gesetzt werden.
Und dann noch:
Delphi-Quellcode:
if richtig then showmessage ('Sie haben Gewonnen');
  ...
if falsch then showmessage ('Sie haben leider verloren');

ScrollbarKopf 18. Dez 2007 16:06

Re: Lotto programm
 
das programm geht jetzt danke hab den klienen fehler behoben aber jetzt kommt keine showmessage

ScrollbarKopf 18. Dez 2007 16:08

Re: Lotto programm
 
was progman
kannst du das bitte erklären

ScrollbarKopf 18. Dez 2007 16:09

Re: Lotto programm
 
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    Edit12: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c,d,e,f :integer;
richtig: boolean;
falsch: boolean;

begin
randomize;
repeat
  a:= random (46);
  b:= random (46);
  c:= random (46);
  d:= random (46);
  e:= random (46);
  f:= random (46);

until (a<>b) and (a<>c) and (a<>d) and (a<>e) and (a<>f)
and  (b<>a) and (b<>c) and (b<>d) and (b<>e) and (b<>f)
and  (c<>a) and (c<>b) and (c<>d) and (c<>d) and (c<>f)
and  (d<>a) and (d<>b) and (d<>c) and (d<>e) and (d<>f)
and  (e<>a) and (e<>b) and (e<>c) and (e<>d) and (e<>f)
and  (f<>a) and (f<>b) and (f<>c) and (f<>d) and (f<>e);

edit1.Text := inttostr (a+1);
edit2.Text := inttostr (b+1);
edit3.Text := inttostr (c+1);
edit4.Text := inttostr (d+1);
edit5.Text := inttostr (e+1);
edit6.Text := inttostr (f+1);

if StrToInt( edit1.text) = StrToInt( edit7.text) then richtig := true ;
if StrToInt( Edit2.text) = StrToInt( Edit8.text) then richtig := true ;
if StrToInt( Edit3.text) = StrToInt( Edit9.text) then richtig := true ;
if StrToInt( Edit4.text) = StrToInt( Edit10.text) then richtig := true ;
if StrToInt( Edit5.text) = StrToInt( Edit11.text) then richtig := true ;
if StrToInt( Edit6.text) = StrToInt( Edit12.text) then richtig := true ;

if richtig then showmessage ('Sie haben Gewonnen');

if StrToInt( Edit1.text) <> StrToInt( Edit7.text) then falsch := false ;
if StrToInt( Edit2.text) <> StrToInt( Edit8.text) then falsch := false ;
if StrToInt( Edit3.text) <> StrToInt( Edit9.text) then falsch := false ;
if StrToInt( Edit4.text) <> StrToInt( Edit10.text) then falsch := false ;
if StrToInt( Edit5.text) <> StrToInt( Edit11.text) then falsch := false ;
if StrToInt( Edit6.text) <> StrToInt( Edit12.text) then falsch := false ;

if falsch then showmessage ('Sie haben leider verloren');

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
edit1.clear;
edit2.clear;
edit3.clear;
edit4.clear;
edit5.clear;
edit6.clear;
edit7.clear;
edit8.clear;
edit9.clear;
edit10.clear;
edit11.clear;
edit12.clear;
end;

end.
Warum kommt jetzt keine showemssage

Progman 18. Dez 2007 16:18

Re: Lotto programm
 
Weil die Methode so nicht klappt. Die Variablen falsch und richtig werden jedesmal gesetzt und behalten demzufolge nur ihren letzten Wert.
Besser wäre es:
Delphi-Quellcode:
var richtige: Integer;

richtige:=0;
if StrToInt( edit1.text) = StrToInt( edit7.text) then inc(richtige); //immer um 1 erhöhen, wenns stimmt
if StrToInt( Edit2.text) = StrToInt( Edit8.text) then inc(richtige) ;
if StrToInt( Edit3.text) = StrToInt( Edit9.text) then inc(richtige) ;
if StrToInt( Edit4.text) = StrToInt( Edit10.text) then inc(richtige) ;
if StrToInt( Edit5.text) = StrToInt( Edit11.text) then inc(richtige) ;
if StrToInt( Edit6.text) = StrToInt( Edit12.text) then inc(richtige) ;
if richtige = 6 then ShowMessage('Hurra!');


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:31 Uhr.
Seite 3 von 4     123 4      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz