Autor Beitrag
claudi89
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 08.01.06 15:40 
Hallo habe folgenden quelltext und delphie soll mir dezimalzahlen ausgeben, tut es aber nicht, könnt ihr mir vielleicht helfen????

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
//******************************************************************************
//                globale Varibeln
Zahl1             :real;
Zahl2             :real;
Rechenzeichen{:+} :string;
result            :real;
//******************************************************************************
implementation

{$R *.dfm}

procedure TForm12.Button_AufgabeStellenClick(Sender: TObject);
begin
randomize;
Zahl1:=random (1000)+1;
Zahl2:=random (1000)+1;
result:=Zahl1+Zahl2;
Label_AufgabeAusgeben.caption:=FloatToStr(Zahl1)+'+'+FloatToStr(Zahl2);
end;




danke schon mal im vorraus

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
andras
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 460

Win XP, Win Vista Home Premium, Ubuntu Dapper Drake
Delphi 2005 Pers
BeitragVerfasst: So 08.01.06 15:43 
probier einmal dasss du variable result anders benennst, weil das ist ein reservierter begriff für den rückgabewert einer funktion. eine procedure kann nichts zurückgeben.
claudi89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 08.01.06 15:47 
das mit dem result ändern bringt nichts er wirft troztdem nur ganze zahlen aus
andras
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 460

Win XP, Win Vista Home Premium, Ubuntu Dapper Drake
Delphi 2005 Pers
BeitragVerfasst: So 08.01.06 15:54 
also so weit ich das verstanden hab, gibt die funktion Random nur integer zurück, außer man übergibt der fuktion random keinen parameter, dann bekommst du einen wert von 0 bis 1 zurück.
änderen deinen quelltext auf das:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var Zahl1:real;
Zahl2,komma1,komma2:real;
Rechenzeichen{:+} :string;
ruckgabewert:real;
begin
randomize;
komma1:=Random;
komma2:=random;
Zahl1:=random (1000)+1+komma1;
Zahl2:=random (1000)+1+komma2;
ruck:=Zahl1+Zahl2;
Label_AufgabeAusgeben.caption:=FloatToStr(Zahl1)+'+'+FloatToStr(Zahl2);
claudi89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 08.01.06 16:04 
cool das funktioniert,
allerdings bekomm ich jetzt 10 zahlen hinter dem komma raus, kann man das auch verkürzen auf 1 oder 2 kommazahlen (ist für ein rechentrainer für 6.klasse)?
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 08.01.06 16:07 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
var
  Form1: TForm1;
  komma1,komma2,Zahl1,Zahl2,Ergebnis:Real;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  randomize;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  komma1:=Random;
  komma2:=random;
  Zahl1:=random (1000)+1+komma1;
  Zahl2:=random (1000)+1+komma2;
  Ergebnis:=Zahl1+komma1+Zahl2+komma2;
  Label1.caption:=FloatToStrF(Zahl1+komma1,fffixed,8,2)+' + '+FloatToStrF(Zahl2+komma2,fffixed,8,2)+ ' = '+FloatToStrF(Ergebnis,fffixed,8,2);
end;
Münzi
Hält's aus hier
Beiträge: 4



BeitragVerfasst: So 08.01.06 16:09 
könntest hieraus eine andere variable z.b. hilfe deklarieren, die dann ausgegeben wird. z.b. mit
Label_AufgabeAusgeben.caption(hilfe, 8:2:string). das müsste soviel bedeuten wie dass eine 8stellige zahl, davon 2 stellen hinter dem kommma angegeben werden. weiß nich ob es auch mit label funktioniert, aba mit edit-boxen auf jeden fall!

edit: gut da is mir wohl jmd zuvorgekommen:)