Autor Beitrag
Titaniumpz
Hält's aus hier
Beiträge: 8

Windows XP
Delphi
BeitragVerfasst: Do 23.11.06 16:46 
Hi,

Letzte Woche wurde mir so gut geholfen - ich hoffe jetzt kann mir wieder wer helfn =).

Aaaaaaaaaaaaaalso das ist so: Wir sollen einen Telefonkostenrechenr basteln mit folgenden Bedingungen
- 1 Einheit kostet 1,5 Cent,
- 20 Einheiten sind gratis,
- Mindestgebühr: 15 Euro

Jetzt habe ich
a) das Problem, dass ich keine Ahnung habe, wie ich das machen soll, dass das Ergebnis nicht im Editfenster, sondern gesondert (vlt. in einem Label?) erscheint
b) ich nicht weiß, wie / wo ich die Befehle strtotint / inttostr verwenden soll (was bringen die eigentlich?) - hat unser Lehrer jesacht

Mein Quellcode, noch ziemlich verbuggt - denke ich - , sieht jetzt so aus (und das Starten geht natürlich auch nicht):

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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Eingabe: TEdit;
    Ausgabe: TLabel;
    Button1: TButton;
    Label6: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

var
  x:integer;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
Eingabe.text:=x;
Inttostr(x);

if x>20
then
  begin
    x:=x-20;
    x:=x*1.5;
    x:=x+15;
    Inttostr(x);
    Ausgabe.caption:=x;
  end
else
  begin
    x:=x+15;
    Inttostr(x);
    Ausgabe.caption:=x;
  end
end;

end.


Dankeschön schon mal im Voraus!

Grüße, Titaniumpz

P.S. Kennt jemand ein gutes Buch, in dem für klein Blöd Delphi erklärt wird bzw. einfach nur Delphi gut u. verständlich beigebracht wird?

Moderiert von user profile iconjasocul: Size-Tags durch Delphi-Tags ersetzt
DaKirsche
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
BeitragVerfasst: Do 23.11.06 16:58 
Zu a)

zum Beschreiben eines Labels verwendest du .Cption, also:
ausblenden Delphi-Quelltext
1:
Label1.Caption:='Ich schreibe nun hier was rein';					


Zu b)

Das ist ganz einfach.....
IntToStr brauchst du, um Integerwerte in Strings umzuwandeln. Alles, was du in irgendeiner Form ausgibst sind Strings....also Zeichenketten
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
[...]
var Kosten:Integer;
begin
Label1.Caption:='Sie zahlen ' + IntToStr(Kosten) + 'Euro und 50 Cent');
end;


Mit StrToInt kannst du das alles in die Andere Richtung laufen lassen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
[...]
var Kosten:Integer;
Txt : String;
begin
Txt:='100';
Kosten:=StrToInt(Txt);
end;

_________________
Die simpelsten Fehler sind meist die Schwersten...
Titaniumpz Threadstarter
Hält's aus hier
Beiträge: 8

Windows XP
Delphi
BeitragVerfasst: Do 23.11.06 17:08 
Okay, danke für die schnelle Hilfe!

Jetzt funktioniert er auch - das Problem ist nur, dass ich mich mit "x:integer" an Ganze Zahlen "binde". Dadurch kann ich jetzt die Einheiten nicht mitm Faktor 1.5 multiplizieren und dann am Ende durch 100 teilen - um eben auf Euros zu kommen! Wie handle ich das denn?

Mein momentaner Quellcode sieht so aus (jetzt eben auf Eurocents ausgerichtet und mit den Kosten einer Einheit von 2 Cent):

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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Eingabe: TEdit;
    Ausgabe: TLabel;
    Button1: TButton;
    Label6: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

var
  x:integer;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
x:=Strtoint(Eingabe.text);

if x>20
then
  begin
    x:=x-20;
    x:=x*2;
    x:=x+150;
    Ausgabe.caption:=inttostr(x);
  end
else
  begin
    x:=150;
    Inttostr(x);
    Ausgabe.caption:=Inttostr(x);
  end
end;

end.


Moderiert von user profile iconjasocul: Size-Tags durch Delphi-Tags ersetzt
Dragonclaw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 196

Windows Vista
Delphi 7 Prof.
BeitragVerfasst: Do 23.11.06 17:10 
ausblenden Delphi-Quelltext
1:
2:
var
x:real;


Reals sind variablen die auch komma zahlen haben können, allerdings musst du dann

inttostr() mit floattostr() austauschen
strtoint() wird zu strtofloat()
DaKirsche
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
BeitragVerfasst: Do 23.11.06 17:11 
Dann deklarierst du deine Variable nicht als Integer, sondern als Float oder Real.
Dann ändert sich IntToStr zu FloatToStr, bzw FloatToStrF(Variable,fffixed,10,2);
Alsomit F ist Runden. fffixed,10,2 sagt aus, dass 10 Stellen angezeigt werden, davon 2 hinterm Komma

_________________
Die simpelsten Fehler sind meist die Schwersten...
DaKirsche
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
BeitragVerfasst: Do 23.11.06 17:14 
Also:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
Procedure TForm1.Button1Click(Sender: TObjact);
var x:Real;
begin
[...]
Label1.Caption:=FloatToStrF(x,fffixed,10,2)
end;

_________________
Die simpelsten Fehler sind meist die Schwersten...
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: Do 23.11.06 17:16 
Hallo Titaniumpz,

wärest Du so freundlich Delphi-Tags statt Size-Tags zu benutzen?

Danke,
Peter
Titaniumpz Threadstarter
Hält's aus hier
Beiträge: 8

Windows XP
Delphi
BeitragVerfasst: Do 23.11.06 17:23 
Ach sorry, habe ich ganz übersehen.

Dankeschön für die rege Hilfe - jetzt klappt's!