Autor Beitrag
LDMatrix17
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 73

xXpProOxsP2x
Flash5~Flash7 MX 2004 Prof.~Flash 8 Prof.~Delphi 7 prof.&HTML
BeitragVerfasst: Mo 09.01.06 21:30 
hallo leute!! ich weiß bin zu schlecht!! ;)

ich habe ne problem
also
Das Programm soll mit hilfe der For-Do-Schleife die Summe aller Werte ermitteln, die zwischen den Werten aus Eingabe1 und eingabe2 liegen. Die Werte aus Eingabe1 und Eingabe2 sind mit zu berücksichtigen, z. B. ist die Summe von 1 und 3 = 1+2+3=6!!


ausblenden 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:
procedure TForm1.bt_forClick(Sender: TObject);
Var
  Zahl1,zahl2,Summe,i,Code : Integer;
begin
//Speichern
  Val(in_eingabe1.Text, Zahl1, Code);
  Val(in_eingabe2.Text, Zahl2, Code);

//prüfen ob zahl1 größer wie zahl 2 ist
  if(zahl1>zahl2) then
   ShowMessage('Der Wert der 2. Eingabe muss größer als der Wert der 1. EIngabe sein!!');

//Schleifen
  Summe :=0;

  For I := zahl1 To zahl2 DO
  begin
   Summe := Summe+I;
  End;

//Ausgeben
  lbl_aus.Caption := ' Die Summe von  '+ FormatFloat('#,###',zahl1)+ 'bis ' + FormatFloat('#,###',Zahl2)+' beträgt bei der For-Schleife '+ FormatFloat('#,###',Summe);


end;


das habe ich auch irgendwie hin gekriegt!!;)
aber jetzt sollen wir !While-Schleife! vornehmen, statt For-Do-Schleife!
kann mir jemand helfen? bitte!

MFG Christian

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: Mo 09.01.06 21:34 
das geht im grunde genauso, nur das du i selber hochzähln musst ;D
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
i:= zahl1;
while i < zahl2 
begin
  Summe := Summe+I; 
  inc(i);
end;
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 09.01.06 21:39 
user profile iconLDMatrix17 hat folgendes geschrieben:


procedure TForm1.bt_forClick(Sender: TObject);
Var
Zahl1,zahl2,Summe,i,Code : Integer;
begin
//Speichern
Val(in_eingabe1.Text, Zahl1, Code);
Val(in_eingabe2.Text, Zahl2, Code);

//prüfen ob zahl1 größer wie zahl 2 ist
if(zahl1>zahl2) then
ShowMessage('Der Wert der 2. Eingabe muss größer als der Wert der 1. EIngabe sein!!');

//Schleifen
Summe :=0;

i := zahl1;
while i <= zahl2 do
//For I := zahl1 To zahl2 DO
begin
Summe := Summe+I;
inc(i);
End;

//Ausgeben
lbl_aus.Caption := ' Die Summe von '+ FormatFloat('#,###',zahl1)+ 'bis ' + FormatFloat('#,###',Zahl2)+' beträgt bei der For-Schleife '+ FormatFloat('#,###',Summe);


end;


MFG Christian


Ironwulf war leider schneller

_________________
Markus Kinzler.
LDMatrix17 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 73

xXpProOxsP2x
Flash5~Flash7 MX 2004 Prof.~Flash 8 Prof.~Delphi 7 prof.&HTML
BeitragVerfasst: Mo 09.01.06 21:53 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
//Schleifen beginnen
  i:=zahl1;
  summe:=0;
  While (i<= Zahl2) DO
   begin
    summe:= summe+i;
    i:=i+1 // gehts auch? statt inc(i)
   End;


Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 09.01.06 21:58 
user profile iconLDMatrix17 hat folgendes geschrieben:

i:=i+1 // gehts auch? statt inc(i)
ja, bringt das gleiche Ergebnis.

_________________
Markus Kinzler.
LDMatrix17 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 73

xXpProOxsP2x
Flash5~Flash7 MX 2004 Prof.~Flash 8 Prof.~Delphi 7 prof.&HTML
BeitragVerfasst: Mo 09.01.06 22:00 
Ihr seit einfach sau coOL!!
Echt danke!! ;)
MFG Christian