Autor Beitrag
ProgrammerGirl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17


D6
BeitragVerfasst: Sa 06.03.04 20:42 
irgenwie geht das trotzdem nicht
ProgrammerGirl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17


D6
BeitragVerfasst: Sa 06.03.04 21:06 
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Panel1: TPanel;
    BtErgebnis: TBitBtn;
    procedure BtErgebnisClick(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}




procedure TForm1.BtErgebnisClick(Sender: TObject);
var Ergebnis, a, b: integer;
begin
a:=StrToInt (Edit1.Text);
b:=StrToInt (Edit2.Text);
Ergebnis:=0;



while  a <> 0 do
if a MOD 2 = 1
then begin
Ergebnis:= Ergebnis + b;
a:= a mod 2;
b:= b*2;
end
else
begin
a:= a DIV 2;
b:= 2*b;
end;

Panel1.Caption:=inttostr(Ergebnis);
end;

end.


Moderiert von user profile iconPeter Lustig: BBCode aktiviert
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Sa 06.03.04 21:45 
Hi du hast noch ein Problem mit dem code du kommst in eine endlosschleife

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
while  a <> 0 do 

if a MOD 2 = 1  //hier muß ein <> stehen kein = Sonst kommst du nie aus dem programm raus weil a immer 1 ist

then begin 
Ergebnis:= Ergebnis + b; 
a:= a mod 2; 
b:= b*2; 
end 
else 
begin 
a:= a DIV 2; 
b:= 2*b; 
end;


Moderiert von user profile iconPeter Lustig: Delphi-Tags hinzugefügt

_________________
it's not a bug it's a feature
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Sa 06.03.04 21:47 
Teste das mal und falls es immer noch nicht geht setze einen Haltepunkt und geh mit f7 in einzelschritten vor dann weiß du wo der fehler zu finden ist

gruß
tmc :twisted:

_________________
it's not a bug it's a feature
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 06.03.04 22:02 
Hallo, @tmc2004 und ProgrammerGirl!

Bitte benutzt demnächst die Delphi-Tags. Durch die Delphi-Tags wird der Code mit Syntax-Highlighting angezeigt und ist somit sehr viel übersichtlicher.

Diese funktionieren natürlich nur, @ProgrammerGirl, wenn BBCode aktiviert ist.

Viele Dank!
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Killmag10
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Sa 06.03.04 22:07 
tmc2004 hat folgendes geschrieben:
Hi du hast noch ein Problem mit dem code du kommst in eine endlosschleife

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
while  a <> 0 do 

if a MOD 2 = 1  //hier muß ein <> stehen kein = Sonst kommst du nie aus dem programm raus weil a immer 1 ist

then begin 
Ergebnis:= Ergebnis + b; 
a:= a mod 2; 
b:= b*2; 
end 
else 
begin 
a:= a DIV 2; 
b:= 2*b; 
end;


Moderiert von user profile iconPeter Lustig: Delphi-Tags hinzugefügt


ich denk mal das er da mit negativen zahlen arbeitet oder ?

weil dann ergibt es auch ihrgentwie in sinn oder so ...

Edit: oder ne doch nett... hab das aus ner falschen perspektive gesehen

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik


Zuletzt bearbeitet von Killmag10 am Sa 06.03.04 22:13, insgesamt 1-mal bearbeitet
ProgrammerGirl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17


D6
BeitragVerfasst: Sa 06.03.04 22:10 
hm da geht schon etwas
aber falsch

wenn ich für a die zahl 4 eingebe und für b auch
steht aufm panel trotzdem 4

es muss ja normalerweise die zahl 16 stehn
Killmag10
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Sa 06.03.04 22:15 
ProgrammerGirl hat folgendes geschrieben:
hm da geht schon etwas
aber falsch

wenn ich für a die zahl 4 eingebe und für b auch
steht aufm panel trotzdem 4

es muss ja normalerweise die zahl 16 stehn


nein

MOD = Rest

Rest von 4 dursch 2 = 0

4 + 0 = 4

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
ProgrammerGirl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17


D6
BeitragVerfasst: Sa 06.03.04 22:45 
aber die schleife soll ja durchlaufen bis a = 0 ist

Beispiel:

a=4
b=5

a (4) MOD 2 ist 0
also soll es
a(4)= a DIV 2
b(5)= 2*b

dann ist
a = 2
b = 10

dann soll es
a(2) MOD 2 = 0
also
a(2)= a DIV 2
b(10)= 2*b

dann ist
a = 1
b = 20

dann soll es
a(1) MOD 2 = 1
also

Ergebnis + b(20) = 20

{a(0)= a DIV 2=0}

b(10)= 2*b = ist b 40



ergebnis ist 20


so soll die schleife fuktionieren, tut es aber nicht
Killmag10
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Sa 06.03.04 22:53 
dann must du es so machen:

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.BtErgebnisClick(Sender: TObject); 
var Ergebnis, a, b: integer; 
begin 
a:=StrToInt (Edit1.Text); 
b:=StrToInt (Edit2.Text); 
Ergebnis:=0; 



while  a <> 0 do 
if a MOD 2 <> 1 
then begin 
a:= a mod 2; 
b:= b*2; 
Ergebnis:= Ergebnis + b; //<---
end 
else 
begin 
a:= a DIV 2; 
b:= 2*b; 
Ergebnis:= Ergebnis + b; //<---
end; 

Panel1.Caption:=inttostr(Ergebnis); 
end;


du must schon mitzählen lassen

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Sa 06.03.04 23:11 
@Programmiergirl du solltest wenn du das nächst mal eine Frage hast vielleicht gleich ein Bsp. mit angeben dann kann man besser nachvollziehen was der Code machen soll. Besonders wenn ein falscher Source da ist.

Gruß
tmc

_________________
it's not a bug it's a feature
ProgrammerGirl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17


D6
BeitragVerfasst: Sa 06.03.04 23:12 
das geht auch nicht
wenn ich 4 und 5 eingebe wird das 10
ProgrammerGirl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17


D6
BeitragVerfasst: Sa 06.03.04 23:15 
@tmc
werde ich machen
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Sa 06.03.04 23:35 
Gebe mal ein paar beispiele an was raus kommen soll zum beispiel bei 5 und 4 ond noch anderen Zaheln.

gruß
tmc

_________________
it's not a bug it's a feature
ProgrammerGirl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17


D6
BeitragVerfasst: Sa 06.03.04 23:39 
egal welche zahl a oder b ist, das ergebnis ist a*b

also
a = 6
b = 6

ergebnis = 36
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Sa 06.03.04 23:39 
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:
procedure TForm1.BtErgebnisClick(Sender: TObject);
var Ergebnis, a, b: integer;
begin
a:=StrToInt (Edit1.Text);
b:=StrToInt (Edit2.Text);
Ergebnis:=0;



while  a <> 0 do
if a MOD 2 = 1
then begin
Ergebnis:= Ergebnis + b;
a:= 0;
end
else
begin
a:= a DIV 2;
b:= 2*b;

end;

Panel1.Caption:=inttostr(Ergebnis);
end;


schau mal ob der so passt

gruß
tmc

Moderiert von user profile iconPeter Lustig: Code- durch Delphi-Tags ersetzt

_________________
it's not a bug it's a feature
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Sa 06.03.04 23:43 
Sorry dann passt es nicht. Wenn ich fragen darf hat das programm auch einen Sinn?

gruß

tmc

_________________
it's not a bug it's a feature
ProgrammerGirl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17


D6
BeitragVerfasst: Sa 06.03.04 23:45 
4 und 4 wird 16

aber 5 und 4 nur 4
Michael Stenzel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 133


D3 Prof, D7 PE
BeitragVerfasst: Sa 06.03.04 23:55 
Hi

probiert es mal so...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.BtErgebnisClick(Sender: TObject);
var Ergebnis, a, b: integer;
begin
  a:=StrToInt (Edit1.Text);
  b:=StrToInt (Edit2.Text);
  Ergebnis:=0;

  while  a <> 0 do
    if (a MOD 2) = 0 then begin
      a:= a div 2;
      b:= b*2;
    end else begin
      Ergebnis:= Ergebnis + b;
      a:= a DIV 2;
      b:= 2*b;
    end;
  Panel1.Caption:=IntToStr(Ergebnis);
end;


mfg
Michael.


Zuletzt bearbeitet von Michael Stenzel am Sa 06.03.04 23:55, insgesamt 1-mal bearbeitet
CABALxx
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 174


D7 Ent
BeitragVerfasst: Sa 06.03.04 23:55 
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var Ergebnis, a, b: integer;
begin
  a:=StrToInt (Edit1.Text);
  b:=StrToInt (Edit2.Text);
  Ergebnis:=0;

  while  a = 0 do
  if a MOD 2 = 1
  then begin
    Ergebnis:= Ergebnis + b;
    a:= a mod 2;
    b:= b*2;
  end
  else
  begin
    a:= a DIV 2;
    b:= 2*b;
  end;


Panel1.Caption:=IntToStr(Ergebnis);
end;
end.


also ich hab mir das mal angekuckt und mal die komplette unit hier gepostet
die is getestet und lässt sich definitiv compilieren

ehmm
aber naja ....... versteh ich was falsch oder is das richtig so das da im Panel am ende immer 0 steht ? :roll: :?
Dieses Thema ist gesperrt, Du kannst keine Beiträge editieren oder beantworten.

Das Thema wurde von einem Team-Mitglied geschlossen. Wenn du mit der Schließung des Themas nicht einverstanden bist, kontaktiere bitte das Team.