Autor Beitrag
LuckyBill
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Mo 29.03.04 15:57 
Hi,
ich soll etwas nach folgender Aufgabenstellung programmieren;

die mitarbeiter der firma x erhalten eine lohnerhöhung um 3.5 %, mindestens jedoch 100€. nach eingabe des alten lohns soll die erhöhung und der neue lohn ausgegeben werden.

So, habe nun das hier geschrieben und weiss nicht wo der fehler ist, könnte das mal jemand bitte verbessern...

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

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure Lohn;
var a,b :real;
begin
  a:=FloatToStr(form1.edit1.text);
  b:=FloatToStr(form1.edit2.text);
  if 3.5/100 a < 100;
   then form1.edit2.text:=strtofloat(b + 100);
   else form1.edit2.text:=strtofloat(b + 3.5/100);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Lohn;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  close;

end;

end.


Moderiert von user profile iconPeter Lustig: Delphi-Tags hinzugefügt
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 29.03.04 16:18 
Ich kommentier mal ein paar Gedanken rein:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure Lohn; 
var a,b :real; 
begin 
  a:=FloatToStr(form1.edit1.text); 
  // Edit1.text ist ein String; a eine Zahl. Also sollte man String to Float konvertieren. Vielleicht klappt ja Strtofloat(), statt FloatToStr...
  b:=FloatToStr(form1.edit2.text); 

  // fehlt hier vielleicht ein Malpunkt ?  Das ist *
  if 3.5/100 a < 100; 
  // und das Semi- ^ -kolon gehört da auch nicht hin!

   then form1.edit2.text:=strtofloat(b + 100); 
  // und hier besser floattostr...               ...^ Das auch weg, vor dem else darf kein ; stehen
   else form1.edit2.text:=strtofloat(b + 3.5/100); 
end;

_________________
We are, we were and will not be.
LuckyBill Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Mo 29.03.04 16:43 
Hi, danke dir... geht aber leider immer noch nicht der motzt in der zweiten zeile und sagt;
[Fehler] Unit1.pas(36): Inkompatible Typen: 'Extended' und 'TCaption'
[Fehler] Unit1.pas(38): Ausdruckstyp muß BOOLEAN sein
[Fehler] Unit1.pas(49): Anweisung erwartet, aber 'PROCEDURE' gefunden
[Fehler] Unit1.pas(17): Ungenügende Forward- oder External-Deklaration: 'TForm1.Button1Click'
[Fataler Fehler] Project1.dpr(5): Verwendete Unit 'Unit1.pas' kann nicht compiliert werden


Hab das jetzt so;
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:
unit Unit1; 

interface 

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

type 
TForm1 = class(TForm) 
Label1: TLabel; 
Edit1: TEdit; 
Label2: TLabel; 
Edit2: TEdit; 
Button1: TButton; 
Button2: TButton; 
procedure Button1Click(Sender: TObject); 
procedure Button2Click(Sender: TObject); 
private 
{ Private-Deklarationen } 
public 
{ Public-Deklarationen } 
end; 

var 
Form1: TForm1; 

implementation 

{$R *.DFM} 

procedure Lohn; 
var a,b :real; 
begin 
a:=Strtofloat (form1.edit1.text); 
b:=FloatToStr(form1.edit2.text); 
if 3.5/100 a < 100 
then form1.edit2.text:=floattostr(b + 100) 
else form1.edit2.text:=strtofloat(b + 3.5/100); 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
Lohn; 

end; 

procedure TForm1.Button2Click(Sender: TObject); 
begin 
close; 

end; 

end.




Also nochmal danke, sorry für die fragen bin halt noch en noob. :)

Moderiert von user profile iconPeter Lustig: Code- durch Delphi-Tags ersetzt
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 29.03.04 17:06 
Du brauchst doch nicht eine eigene Procedure für "Lohn"
Mach mal "Lohn" in die Button Procedure.

ausblenden Delphi-Quelltext
1:
if 3.5/100 a < 100					

Das versteh ich noch nicht ganz.
Angenommen, "a" ist gleich "5"
Dan würde das heißen:
ausblenden Delphi-Quelltext
1:
if 3.5/100 5 < 100					

Das ist doch keine Rechnung, oder?!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 29.03.04 17:17 
So, jetzt kommen meine Gedanken! :-)

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

interface 

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

type 
TForm1 = class(TForm) 
Label1: TLabel; 
Edit1: TEdit; 
Label2: TLabel; 
Edit2: TEdit; 
Button1: TButton; 
Button2: TButton; 
procedure Button1Click(Sender: TObject); 
procedure Button2Click(Sender: TObject); 
private 
{ Private-Deklarationen } 
public 
{ Public-Deklarationen } 
end; 

var 
Form1: TForm1; 

implementation 

{$R *.DFM} 

procedure Lohn; 
var a,b :real; 
begin 
a:=Strtofloat (form1.edit1.text); 
b:=FloatToStr(form1.edit2.text); //Dasselbe wie bei a! Warum auch andersrum? 
if 3.5/100 a < 100 //Immer noch derselbe Fehler. Es soll wohl 3.5/100*a heißen, oder sowas ...
then form1.edit2.text:=floattostr(b + 100) 
else form1.edit2.text:=strtofloat(b + 3.5/100); 
end; 

procedure TForm1.Button1Click(Sender: TObject);
begin 
Lohn; 

end; 

procedure TForm1.Button2Click(Sender: TObject); 
begin 
close; 

end; 

end.


//Edit: @GTA-Place: eine eigene Procedure ist schon richtig.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 29.03.04 17:19 
Eben, ist doch keine Rechnung
ausblenden Delphi-Quelltext
1:
if 3.5/100 a < 100					


Und so muss das:
ausblenden Delphi-Quelltext
1:
2:
a := StrToFloat(form1.edit1.text);
b := StrToFloat(form1.edit2.text);



PS: Mir sagt man immer ich soll Tuts lesen, und der brauch das nicht?!


EDIT: Aber er kanns ja auch in eine Procedure, oder? Dann kommt immerhin ein Fehler weniger.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 29.03.04 17:21 
Zitat:
PS: Mir sagt man immer ich soll Tuts lesen, und der brauch das nicht?!
Bei ihm ist offensichtlich, dass er sich damit beschäftigt und nicht im Netz nach Codeschnipseln zum zusammenkitten sucht.

Zitat:
EDIT: Aber er kanns ja auch in eine Procedure, oder? Dann kommt immerhin ein Fehler weniger.
Hä? :-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 29.03.04 17:23 
Ich mach die meisten Codes auch selber :evil:


EDIT: [Fehler] Unit1.pas(49): Anweisung erwartet, aber 'PROCEDURE' gefunden
Der Fehler fällt weg.

EDIT2:
Und so kommt kein Fehler mehr:

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

interface  

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

type  
TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

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

var
Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.Button1Click(Sender: TObject); 
var a,b :real;
begin
a:=Strtofloat (form1.edit1.text);
b:=Strtofloat(form1.edit2.text); 
if 3.5/100 + a < 100 //Aus dem + machen was du brauchst
then form1.edit2.text:=floattostr(b + 100)
else form1.edit2.text:=floattostr(b + 3.5/100);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;

end.
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 29.03.04 17:29 
Hab den Code grade mal kopiert und getestet, und es sind nur die Fehler drin, die ich schon korrigiert habe. Nur manchmal kommt eben ein fehler mehrfach vor, z.b. die Verwechslung strtofloat und floattostr.
Aber da ich ja auch ein paar Kleinigkeiten erklärt habe, verfällt mir nun auch ldie Lust, hier noch weitere Tips zu geben, und verweise mal auf die Delphi-Grundlagen, die man sich vielleich erst mal ansehen sollte...

Ach mist, zu langsam. Das kommt davon, wenn man erst auf antworten klickt, dann was essen geht, und dann schreibt und absendet...

_________________
We are, we were and will not be.


Zuletzt bearbeitet von Gausi am Mo 29.03.04 17:33, insgesamt 1-mal bearbeitet
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 29.03.04 17:31 
Meinen Code?
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 29.03.04 17:34 
nein, nicht deinen, sondern den fehlerhaften von davor, der aber schon von Peter Lustig verbessert wurde. Deiner sollte ok sein... bis auf das Plus-zeichen :lol:

_________________
We are, we were and will not be.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 29.03.04 17:35 
Zitat:
EDIT: [Fehler] Unit1.pas(49): Anweisung erwartet, aber 'PROCEDURE' gefunden
Der Fehler fällt weg.
Ich denke, man sollte den Fehler beseitigen, nicht den Code. ;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 29.03.04 17:35 
Der Code geht ja jetzt.
Alle Fehler sind weg!
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 29.03.04 17:37 
ohh....sag das nicht, man kann da bestimmt was falsch abtippen.... :twisted:

_________________
We are, we were and will not be.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 29.03.04 17:41 
Also bei mir gehts
Habs getestet!
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 29.03.04 17:50 
Das will ich ja auch gar nicht bestreiten...Ich glaube wir schreiben aneinander vorbei.

Mehr schreibe ich nicht, sonst könnte das wer anders in den falschen Hals kriegen, und ich möchte hier keinen vergraulen. Schließlich hat hier jeder mal n Brett vorm Kopf gehabt...Und die Bretter von den Neulingen sind halt anders gebaut als die von den etwas erfahreneren Delphianern.

_________________
We are, we were and will not be.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 29.03.04 17:52 
Ahja...
OK :D
LuckyBill Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Mo 29.03.04 20:39 
Leute ich bin euch echt zu tiefst dankabr aber ich bekomme immer noch ne FEHLERMELDUNG :shock:

Das Programm startet zwar aber ich bekomme die meldung "keine gültige gleitkommazahl"
und dann brichtd as Programm ab, ich hab Delphi 5 und denke das das Programm mich auf den arm nimmt...

Kann schon keinen Code mehr sehen ;)

Danke nochmals!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 29.03.04 20:51 
Dann ist eine der Zahlen in den Edit-Feldern keine Zahl in dem Sinne, wie Delphi sie versteht. Welches Dezimaltrennzeichen hast Du benutzt? Punkt oder Komma?

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

Win 2000, Linux
D2005 Prof
BeitragVerfasst: Di 30.03.04 12:40 
Zitat:
[...] Mehr schreibe ich nicht, sonst könnte das wer anders in den falschen Hals kriegen, [...]

he he und jetzt misch ich mich auch mal ein... :P
Kommen wir nochmal auf die ursprüngliche Frage zurück:
Zitat:
die mitarbeiter der firma x erhalten eine lohnerhöhung um 3.5 %, mindestens jedoch 100€. nach eingabe des alten lohns soll die erhöhung und der neue lohn ausgegeben werden.

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

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure Lohn;
var
  a, b: real;
begin
  a := StrToFloatDef(Form1.Edit1.Text, 0); // alter Lohn, wenn ungültig, dann 0
  b := a * 3.5 / 100; // Erhöhung errechnen
  if b < 100 then // wenn zu wenig (wie immer :D )
    b := 100;
  a := a + b;
  Form1.Label1.Caption := FloatToStr(b); // Erhöhung
  Form1.Label2.Caption := FloatToStr(a); // neuer Lohn
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Lohn;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Close;
end;

end.


Gruß
Sven

_________________
Das Denken ist die schwierigste Arbeit für einen Menschen. Deswegen beschäftigen sich ja auch nur so wenige damit...