Einzelnen Beitrag anzeigen

Klaus01
Online

Registriert seit: 30. Nov 2005
Ort: München
5.757 Beiträge
 
Delphi 10.4 Sydney
 
#19

Re: Inkompatible Typen

  Alt 9. Mai 2007, 08:19
Habe in Deinem Code mal etwas rumeditiert.

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
Var
  Ziehung, Tipp: Array[1..6] of Extended;
  Anzahl, Nummern: Integer;
  Zahl: Extended;
  Richtig: Integer;
  Vorhanden: Boolean;
  Visible: Boolean;
  I: Integer;
  MinWert, MaxWert: Extended;
begin
  MinWert:= 1;
  MaxWert:= 49;
  for I := 1 to Length(Tipp) do
  begin
    //if ( Tipp[I - 1] < MinWert ) then Tipp[0] ist in Deinem Array nicht definiert
    if ((Tipp[i] < MinWert) and (Tipp[i] > MaxWert)) then // bewegt sich der Tipp ausserhalb der Grenzen
                                                           //(würde ich schon bei der Eingabe abfangen wollen
      begin
        ShowMessage('Ungültige Eingabe...');
        break;
      end
    else
      begin
        Ziehung[1] := 1 + Random(49);
        Anzahl:=2;
        Repeat
          Zahl := 1 + Random(49);
          Nummern := 1;
          Vorhanden := False;
          Repeat
            if ( Zahl <> Ziehung[Nummern] ) then
            begin
              Nummern := Nummern + 1;
            end
            else
            begin
              Vorhanden := True;
            end;
          Until ( (Anzahl = Nummern) or Vorhanden );
          if ( not Vorhanden ) then
            begin
              Ziehung[Anzahl] := Zahl;
              Anzahl := Anzahl + 1;
            end;
        Until ( Anzahl > 6 );
        Zahl1.Text := FloatToStr(Ziehung[1]);
        Zahl2.Text := FloatToStr(Ziehung[2]);
        Zahl3.Text := FloatToStr(Ziehung[3]);
        Zahl4.Text := FloatToStr(Ziehung[4]);
        Zahl5.Text := FloatToStr(Ziehung[5]);
        Zahl6.Text := FloatToStr(Ziehung[6]);
        Tipp[1] := StrToFloat(Tipp1.Text);
        Tipp[2] := StrToFloat(Tipp2.Text);
        Tipp[3] := StrToFloat(Tipp3.Text);
        Tipp[4] := StrToFloat(Tipp4.Text);
        Tipp[5] := StrToFloat(Tipp5.Text);
        Tipp[6] := StrToFloat(Tipp6.Text);
        Richtig := 0;
        for Nummern := 1 to 6 do
          begin
            for Anzahl := 1 to 6 do
              begin
                if ( Ziehung[Nummern] = Tipp[Anzahl] ) then
                Inc(Richtig);
              end;
            if ( Richtig < 2 ) then
            begin
              Kommentar.Caption := 'Miserable Leistung';
            end;
            if ( Richtig = 2 ) then
            begin
              Kommentar.Caption := 'Naja wenigstens etwas!';
            end;
            if ( Richtig > 2 ) then
            begin
              Kommentar.Caption := 'Du kommst dem Ziel näher..';
            end;
            if ( Richtig > 4 ) then
            begin
              Kommentar.Caption := 'Ich denke das kann was werden bei dir!!!';
            end;
            if ( Richtig = 6 ) then
            begin
              Kommentar.Caption := 'Du hast alle übertroffen die Million is dein!!';
            end;
          end;
      end;
      Richtige.Text := FloatToStr(Richtig);
      Kommentar.Visible := True;
    end;
  end;
end;
nicht getestet!!

Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat