Autor Beitrag
loid
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 57

win xp,sp2
d7 pers,free pascal
BeitragVerfasst: Sa 24.09.05 21:51 
hallo,
also es ist eigentlich nur ein testprogramm,ich kann es kompilieren aber er zeigt mir das ergebnis nicht an!
Hier das programm:

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:
60:
unit Unit3;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    Panel1: TPanel;
    Edit4: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var a,b,c:integer;
begin
a:=StrToInt(edit1.text);
b:=StrToInt(edit2.Text);
c:=StrToInt(edit3.Text);
c:=a div 100;
c:=c div b;
edit3.Text:=IntToStr(c);
if c>8 then
begin
edit4.Text:='Viel zu viel!';
end;
if c<=4 then
begin
edit4.text:='Lupo oder was?!';
end;
end;

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

end.


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 24.09.05 22:33 
Du hättest vieleicht deinen Variablen mal Namen geben können.
Dann könnte man das vieleicht nachvollziehen.
Eigentlich Brauchst Du nur Die Getankten Liter / die gefahrenen Kilometer * 100 und schon hast du deinen Verbrauch.
Also Verbrauch:=A div B *100;
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Sa 24.09.05 23:00 
Hallo,

versuch mal es zu interpretieren / kommentieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
a:=StrToInt(edit1.text);//gefahrene Kilometer  500 Kilometer
b:=StrToInt(edit2.Text);//Benzinverbrauch       30 Liter
c:=StrToInt(edit3.Text);//Edit3.Text in c kopieren ???, wird im nachfolgenden Code überschrieben
c:=a div 100;// >> 500/100 = 5 (Faktor)
//c:=c div b;// Formelansatz falsch >> 5 / 30  = 0  FEHLER 1
c:=b div c;  // so ist es richtig   >> 30 / 5  = 6
edit3.Text:=IntToStr(c);
if c>8 then//mehr als 8 Liter Verbrauch
begin
edit4.Text:='Viel zu viel!';
end;
if c<=4 then//weniger als 5 Liter Verbrauch
begin
edit4.text:='Lupo oder was?!';
end;


Ergebnis 5,6,7 u. 8 Liter Verbrauch wird nicht ausgewertet.
Da fehlt noch eine else-Zweig

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
blaueled
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 133

Win XP
D5
BeitragVerfasst: Sa 24.09.05 23:30 
Hallo,

Der Ansatz ist außerdem auch falsch:
wenn man so ein Prog bräuchte, dann muss es etwas bequemer sein.

Man geht davon aus, das du 2 Tankstellen - Bons hast:
bon1:
bei 0015236 km
24,31 Liter getankt.

bon2:
bei 0015358 km
34,48 Liter getankt

Die gefahrenen Kilometer lassen sich noch einfach auswerten.
0015358 - 0015236 = 100 ! ;-)
Beim Benzin ist es schon schwieriger:
1. du gehst davon aus, dass die Person immer nur tankt, wenn der
Tank total leer ist.
2. du gehst davon aus, dass immer vollgetankt wird:
34,48 - 24,31 = 10,17

Dann hättest du:
10,17 / (100/100) = 10.17 l/100km

Arne
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 25.09.05 03:43 
Das Letzte gefällt mir am Besten.
10,17 / (100/100) = 10.17 l/100km
loid Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 57

win xp,sp2
d7 pers,free pascal
BeitragVerfasst: So 25.09.05 10:23 
hier noch mal für blackheart666.


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
var kilometer,sprit,verbrauch:integer;
begin
kilometer:=StrToInt(edit1.text);
sprit:=StrToInt(edit2.Text);
verbrauch:=StrToInt(edit3.Text);

verbrauch:=kilometer div 100;
verbrauch:=sprit div verbrauch;
edit3.Text:=IntToStr(verbrauch);
if verbrauch>8 then
begin
edit4.Text:='Viel zu viel!';
end;
if verbrauch<=4 then
begin
edit4.text:='Lupo oder was?!';
end;
end;


@lannes: wenn ich jetzt zwei zahlen eingebe,bekomme ich die fehlermeldung:is not a valid integer value.warum nicht?
@blaueled:warum ist der ansatz falsch?ich wollte nur ein einfaches prog machen.verbesserungen sind natürlich immer möglich!trotzdem danke
loid

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
blaueled
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 133

Win XP
D5
BeitragVerfasst: So 25.09.05 10:50 
Hallo,

es ist natürlich nicht falsch, aber der Benutzer mussn erin bisschen denken ...

Integer sind negative und positive ganzzahlen, also nur
...,-2,-1,0,1,2,...
Wenn du 10,17 eingibst, gibt es einen Fehler,
nimm einfach float, wie in meinem Beispiel ...
dann kannst du auch das div durch / ersetzen.
bzw:
ausblenden Delphi-Quelltext
1:
kilometer:=round(StrTofloat(edit1.text));					



Arne
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 25.09.05 12:16 
Kleiner Ansatz
Stells Dir um wie du's brauchst

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
 var
  GetankteLiter, GefahreneKilometer, Verbrauch:Real;
begin
  GetankteLiter:= StrToFloat(Edit1.Text);
  GefahreneKilometer:= StrToFloat(Edit2.Text);
  Verbrauch:=GetankteLiter / GefahreneKilometer * 100;
  Label1.Caption:=FloatToStrF(Verbrauch,fffixed,8,2);
end;
loid Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 57

win xp,sp2
d7 pers,free pascal
BeitragVerfasst: So 25.09.05 12:33 
ok danke habs hinbekommen.(eigentlich völlig banal,ich weiss)
loid