Autor Beitrag
Maisinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 167

Win XP HE SP3, Win Vista HP SP2
Delphi ;-)
BeitragVerfasst: Mi 05.11.08 17:08 
hallo,
ich hab ein kleines problem
ich soll als HA einen "rechner" programmieren, der guckt, welche 4-stellige zahl, eine bestimmte bedinung erfüllt.
Bsp: 2025-->
20+25=45
45*45=2025

meine quellcode lautet:

var
zahl, vorne, hinten, summe: integer;
begin
for zahl:= 1000 to 9999 do
begin
vorne:= zahl div 100;
hinten:= zahl mod 100;
summe:= vorne+hinten;
end;
end;

nun weiß ich jedoch net, wie ich es schaffe, wenn eine zahl die bedinung erfüllt, dass sie mir dann in meinen label1 angezeigt wird.
kann mir jemand helfen????
(bei einem if-befehl krieg ich immer die meldung: string und integer sind unkompatibel)
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: Mi 05.11.08 17:59 
Wenn ich deine Aufgabe richtig verstehe, musst du nur noch überprüfen, ob summe*summe das gleiche ist wie zahl; dabei tauchen keine Strings auf.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Mi 05.11.08 18:25 
Hi und :welcome: im Delphi-Forum,

Du hast dir ja mit den Color-Tags ganz viel Mühe gegeben, spitze :zustimm:

Brauchst du aber nicht, es gibt Delphi-Tags ;)
ausblenden Delphi-Tags:
1:
  <span class="inlineSyntax"><span class="codecomment">{PROTECTTAGdb7efc0e7442ea39a506ab97ec09eab2}</span></span>					


Einzelne Stellen markierst du mit dem
Highlight-Tag:

[highlight] markierte Stelle [/highlight]


mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)


Zuletzt bearbeitet von Hidden am Do 06.11.08 18:28, insgesamt 1-mal bearbeitet
demdem
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Mi 05.11.08 18:41 
Hi Hidden ^^

ich glaube du musst den befehl : InttoStr( 'Zahl') benutzen, damit das Label die Zahl in String konvertieren kann ...

als z.B.


If Bedingung erfüllt, dann kommt X raus ;

Form1.Label1.Caption := inttoStr(X);


glaube ich ^^ ... aber ich bin auch noch ein Anfänger in dem Bereich

Gruß demdem
Maisinator Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 167

Win XP HE SP3, Win Vista HP SP2
Delphi ;-)
BeitragVerfasst: Mi 05.11.08 23:07 
schon ma danke für die antworten!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
zahl, vorne, hinten, summe, zahlneu:integer;
begin
for zahl:= 1000 to 9999 do
  begin
  vorne:=zahl div 100;
  hinten:= zahl mod 100;
  summe:= vorne+hinten;
  zahlneu:= summe*summe;
  end;
  if zahlneu = zahl then
  Label1.Caption:= IntToStr (zahlneu);
  end;

wenn ich es so mache, krieg ich gar keine zahl im label

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
ar
zahl, vorne, hinten, summe, zahlneu:integer;
begin
for zahl:= 1000 to 9999 do
  begin
  vorne:=zahl div 100;
  hinten:= zahl mod 100;
  summe:= vorne+hinten;
  zahlneu:= summe*summe;
  end;
  Label1.Caption:= IntToStr (zahlneu);
  end;

und wenn ichs so mache, wird mir irgendwas mit 39000 angezeigt, dabei will ich ja ne 4-stellige zahl.
weiß noch jemand einen rat????
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Do 06.11.08 00:22 
user profile iconMaisinator hat folgendes geschrieben Zum zitierten Posting springen:
schon ma danke für die antworten!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
zahl, vorne, hinten, summe, zahlneu:integer;
begin
for zahl:= 1000 to 9999 do
  begin
  vorne:=zahl div 100;
  hinten:= zahl mod 100;
  summe:= vorne+hinten;
  zahlneu:= summe*summe;
  end;
  if zahlneu = zahl then
  Label1.Caption:= IntToStr (zahlneu);
  end;

wenn ich es so mache, krieg ich gar keine zahl im label

Ist auch klar, wie ordentliche Formatierung zeigt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
zahl, vorne, hinten, summe, zahlneu:integer;
begin
  for zahl:= 1000 to 9999 do begin
    vorne:=zahl div 100;
    hinten:= zahl mod 100;
    summe:= vorne+hinten;
    zahlneu:= summe*summe;
  end;

  if zahlneu = zahl then
    Label1.Caption:= IntToStr (zahlneu);
end;

Nach der Schleife ist das relativ sinnlos: :arrow: das if in den begin...end-Block der Schleife verschieben.

user profile iconMaisinator hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
for zahl:= 1000 to 9999 do
  begin
{...}
  end;
  Label1.Caption:= IntToStr (zahlneu);
  end;

und wenn ichs so mache, wird mir irgendwas mit 39000 angezeigt, dabei will ich ja ne 4-stellige zahl.
weiß noch jemand einen rat????

Wie gesagt... nach der Schleife bringt das nichts. Was du hier machst ist den letzten Wert von zahlneu anzuzeigen (und zwar ohne Bedingung) und das ist (99+99)^2=39204.

cu
Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
martin300
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 186
Erhaltene Danke: 2



BeitragVerfasst: Do 06.11.08 01:02 
Hi,
eine vierstellige Zahl geht von 0000 bis 9999. In deiner Lösung werden nicht alle Zahlen
abgedeckt. Mein Tipp die Zahlen teilen.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Do 06.11.08 01:29 
Naja. Die 'umgangssprachliche' Variante von vierstellig enthält aber kein Zero-Padding...

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Logikmensch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 390

Win XP
Delphi 2007 Prof., XE2, XE5
BeitragVerfasst: Do 06.11.08 07:03 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var  
  zahl, vorne, hinten, summe, zahlneu:integer;  
begin  
  for zahl:= 1000 to 9999 do begin  
    vorne:=zahl div 100;  
    hinten:= zahl mod 100;  
    summe:= vorne+hinten;  
    zahlneu:= summe*summe;  
    if zahlneu = zahl then begin 
      Label1.Caption:= IntToStr (zahlneu);  
      break;
    end;
  end;   
end;

_________________
Es gibt keine Probleme - nur Lösungen!
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Do 06.11.08 08:57 
Beziehungsweise gleich in ein Memo statt ein Label ausgeben, ich vermute ja mal da gibt es mehrere Lösungen.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Maisinator Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 167

Win XP HE SP3, Win Vista HP SP2
Delphi ;-)
BeitragVerfasst: Do 06.11.08 17:29 
und wofür is der brake????
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var  
  zahl, vorne, hinten, summe, zahlneu:integer;  
begin  
  for zahl:= 1000 to 9999 do begin  
    vorne:=zahl div 100;  
    hinten:= zahl mod 100;  
    summe:= vorne+hinten;  
    zahlneu:= summe*summe;  
    if zahlneu = zahl then begin 
      Label1.Caption:= IntToStr (zahlneu);  
      <span style="color: orange">break;</span>
    end;
  end;   
end;

aba sonst danke!
ps: wie wärs dann mit nem memo feld????
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Do 06.11.08 18:27 
Immer mal Delphi-Hilfe fragen: Cursor im Delphi-Editor auf das Wort, F1 drücken, erleuchtet werden :think:

break verlässt eine Schleife. Hat hier den Zweck dass er nach dem er was ins Label geschrieben hat nicht mehr weitergrübelt. Ansonsten würde er bei ggf. auftretenden weiteren Funden das halt wieder Überschreiben. Deswegen auch das mit dem Memo.

Damit sind wir bei Punkt 2: gleich mal Hilfe nutzen üben ;) Stichwort: TMemo.Lines

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."