Autor Beitrag
Haraldo
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 38

XP Prof.
delphi6 und 7
BeitragVerfasst: Mo 27.11.06 16:11 
ich bin zu blöd
ich habe eine aufgabe wie folgt
te := a*links
a = 2
links = -1
ergebnis te = 0 ist aber falsch
weis jemad warum, dringende hausaufgaben


Moderiert von user profile iconGausi: Topic aus Sonstiges (Delphi) verschoben am Mo 27.11.2006 um 16:13
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 27.11.06 16:13 
2 mal -1 ist -2. Wie kommst du auf 0?

_________________
We are, we were and will not be.
Haraldo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 38

XP Prof.
delphi6 und 7
BeitragVerfasst: Mo 27.11.06 16:29 
genau das ist mein prob
var a,links,te :real;
a:= 2;
links := -1;
te := a*links
dann bekomme ich als ergenis te = 0 muss aber -2 sein und ich weis nicht warum
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Mo 27.11.06 16:33 
Sehr sehr seltsam... Was kommt wenn links 1 wäre?
Haraldo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 38

XP Prof.
delphi6 und 7
BeitragVerfasst: Mo 27.11.06 16:35 
komischerweise auch te=0
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Mo 27.11.06 16:36 
Zeig den ganzen Code, so kann eigentlich nix falsch sein. :shock:
Haraldo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 38

XP Prof.
delphi6 und 7
BeitragVerfasst: Mo 27.11.06 16:38 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var a,links,te :real;
begin
 a:= 2;
 links := strtofloat(edit1.text);
 te := (a*(links));
 label12.caption := floattostr(te);
end;


Moderiert von user profile iconjasocul: Delphi-Tags hinzugefügt
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Mo 27.11.06 16:41 
Versuchs mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var 
  a, links, te: Integer; 
begin 
  a := 2; 
  links := StrToInt(Edit1.Text); 
  te := a * links; 
  Label12.Caption := IntToStr(te); 
end;

Oder etwas kürzer:
ausblenden Delphi-Quelltext
1:
2:
3:
begin
  Label12.Caption := IntToStr(2 * StrToInt(Edit1.Text));
end;

Und verwende nächstes Mal bitte "Delphi-Tags", dann kann man deinen Quelltext besser lesen ;)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 27.11.06 16:52 
Bei mir funktioniert der Code von Haraldo einwandfrei. Der Fehler ist woanders zu suchen.
Haraldo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 38

XP Prof.
delphi6 und 7
BeitragVerfasst: Mo 27.11.06 16:53 
wenn ich es als einzelne procedure mache klappt es sowohl mit real als auch mit integer aber in meiner procdure steht das selbe kommt aber 0 raus
VaNaTiC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30



BeitragVerfasst: Mo 27.11.06 17:00 
Bei mir funktioniert es genauso, wie bei jasocul.
Ich denke nicht, dass an dem geposteten Quellcode ein Fehler ist.

Bitte prüfe doch Deine Eingaben im Edit1.Text per Debugger und dann das Zwischenergebnis in links auch so.
monster
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 51

Win XP
Delphi 2005 PE
BeitragVerfasst: Mo 27.11.06 17:09 
mich würde mal interessieren: welchen wert hat edit1.text zum fraglichen Zeitpunkt und welchen Wert hat strToFloat(edit1.text)? Überprüf das mal, entweder mit Haltepunkten und dem Debugger oder mit Showmessage(edit1.text + ' (' + strToFloat(edit1.text) + ')');
Haraldo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 38

XP Prof.
delphi6 und 7
BeitragVerfasst: Mo 27.11.06 17:32 
beim debuggen haben a und links bzw lgrenze -1

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
                ////////Intervallhalbierungsverfahren/////////
///////////////////////////////////////////////////////////////////////////////
procedure TFProgramm.BerechnenIntervallClick(Sender: TObject);
///////////////////////////////////////////////////////////////////////////////
var   LGrenze2,RGrenze2,RGrenze3,m2,m3,RGrenze,m,fLGrenze,fRGrenze,fm,b,old:real;
      NachStell, durchl:integer;
      te1,a,lgrenze3,lgrenze:real;
begin
        fLGrenze:=0;
        fRGrenze:=0;
        fm:=0;
        a:=0;
        b:=0;
        LGrenze:=0;
        LGrenze2:=0;
        LGrenze3:=0;
        RGrenze:=0;
        RGrenze2:=0;
        RGrenze3:=0;
        m:=0;
        m2:=0;
        m3:=0;
        NachStell:=0;          //Nachstell wird auf Null gesetzt, als Anfangswert
        durchl:=0;             //durchl wird auf Null gesetzt, als Anfangswert
        old:=0;
        te1:=0;
        if strtoint(Edit5.Text) >18 then
         begin
          showmessage('Maximal 18 Nachkommastellen möglich!');
          edit5.Text:='';
          edit5.SetFocus;
          exit;
         end;
        NachStell:= strtoint(Edit5.text);  //Nachkommastelle ist Wert der in Fenster Edit1 eingegeben wird(vorher Edit1 zu integer umgewandelt

        LGrenze:=strtoint(Edit3.text);
        RGrenze:=strtoint(Edit4.text);

        While LGrenze<>OLD Do
         Begin
          inc(durchl);
          m:= ((LGrenze+RGrenze)/2);

          a:=2;
          b:=3;
          LGrenze2:=(LGrenze)*(LGrenze);
          LGrenze3:=(LGrenze)*(LGrenze)*(LGrenze);
          RGrenze2:=(RGrenze)*(RGrenze);
          RGrenze3:=(RGrenze)*(RGrenze)*(RGrenze);
          m2:=(m)*(m);
          m3:=(m)*(m)*(m);

          te1 := ((a)*(lgrenze3));


          fLGrenze:= (((a*(LGrenze3))+(LGrenze2))-(b*(LGrenze)));
          fRGrenze:= (((a*RGrenze3)+(RGrenze2))-(b*RGrenze));
          fm:= (((a*m3)+m2)-(b*m));


          If ((fLGrenze<0) and (fm>0)) or ((fLGrenze >0) and (fm<0)) then
           Begin
            old:=LGrenze;
            LGrenze:=flGrenze;
            RGrenze:=fm;
           end
          else
          If ((fm<0) and (fRGrenze>0)) or ((fm >0) and (fRGrenze<0)) then
           Begin
            old:=LGrenze;
            LGrenze:=fm;
            RGrenze:=fRGrenze;
           end;

         end;

       label21.Caption:=inttostr(durchl);
       label15.Caption:=floattostr(LGrenze);


        label22.Caption:=floattostr(NachStell);
        label23.Caption:=floattostr(LGrenze2);
        label24.Caption:=floattostr(LGrenze3);
        label25.Caption:=floattostr(RGrenze2);
        label26.Caption:=floattostr(RGrenze3);
        label27.Caption:=floattostr(m2);
        label28.Caption:=floattostr(m3);
        label29.Caption:=floattostr(LGrenze);
        label30.Caption:=floattostr(RGrenze);
        label31.Caption:=floattostr(m);
        label32.Caption:=floattostr(fLGrenze);
        label33.Caption:=floattostr(fRGrenze);
        label34.Caption:=floattostr(fm);
end;


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt