Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi Procedure Programm Hilfe (https://www.delphipraxis.net/161468-delphi-procedure-programm-hilfe.html)

Jasmin 5. Jul 2011 09:11


Delphi Procedure Programm Hilfe
 
Hallo, ich soll für die Schule folgendes programmieren:
Schreibe ein Programm das folgende Funktion y = 2x² +c berechnet. Verwende für die Berechnung eine selbst geschriebene Prozedur. (Eingabe: x und c)

Ich habs so probiert.. was ist falsch?

Delphi-Quellcode:
var y : real;
procedure pformel (x, c : real);
begin
y:= 2*(x*x) + c ;
end;


procedure TForm1.Button1Click(Sender: TObject);
var x, c : real;
begin
x := StrToFloat (Edit1.text);
c := StrToFloat (Edit2.text);
pformel (x, c);
panel1.caption := FloatToStr (y)
end;

mleyen 5. Jul 2011 09:15

AW: Delphi Procedure Programm Hilfe
 
Delphi-Quellcode:
2x² +c
ist nicht:
Delphi-Quellcode:
2*(x*x) + c ;
Potenziert wird mit Delphi-Referenz durchsuchenpower

Delphi-Quellcode:
power(x*x,2) + c ;
edit: quatsch, sorry eigentlich is da nix falsch...

Jasmin 5. Jul 2011 09:19

AW: Delphi Procedure Programm Hilfe
 
ich hab das mit power nie gelernt, ich hab noch delphi 6.

pHL 5. Jul 2011 09:20

AW: Delphi Procedure Programm Hilfe
 
Gehört das nicht so?
Delphi-Quellcode:
power(x,2)


mfg

hitzi 5. Jul 2011 09:21

AW: Delphi Procedure Programm Hilfe
 
[edit] Sorry, das y fehlt doch nicht. Ist ja eine globale Variable ...

DeddyH 5. Jul 2011 09:22

AW: Delphi Procedure Programm Hilfe
 
Was ist denn überhaupt falsch? Meckert der Compiler, oder stimmt das Ergebnis nicht? Ich sehe jedenfalls keine Fehler auf den ersten Blick.

[edit] y ist eine globale Variable, welche innerhalb der Prozedur berechnet wird. [/edit]

Jasmin 5. Jul 2011 09:56

AW: Delphi Procedure Programm Hilfe
 
als ergebnis zeigt das panel immer 0

Luckie 5. Jul 2011 10:01

AW: Delphi Procedure Programm Hilfe
 
Wenn x und c null sind stimmt das doch.

mleyen 5. Jul 2011 10:06

AW: Delphi Procedure Programm Hilfe
 
Änder mal testweise das Button-Event so ab:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  x, c : real;
begin
  x := StrToFloat (Edit1.text);
  c := StrToFloat (Edit2.text);
  pformel (x, c);
  ShowMessage('2* '+Edit1.text+'² +'+Edit2.text+' = '+FloatToStr (y));
end;
Wird nun ein Dialog angezeit?
Was zeigt der?

DeddyH 5. Jul 2011 10:06

AW: Delphi Procedure Programm Hilfe
 
Also, bei mir funktioniert der Quelltext. Z.B. 5 in Edit1 und 3 in Edit2 ergibt 53.


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:45 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz