![]() |
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; |
AW: Delphi Procedure Programm Hilfe
Delphi-Quellcode:
ist nicht:
2x² +c
Delphi-Quellcode:
Potenziert wird mit
2*(x*x) + c ;
![]()
Delphi-Quellcode:
edit: quatsch, sorry eigentlich is da nix falsch...
power(x*x,2) + c ;
|
AW: Delphi Procedure Programm Hilfe
ich hab das mit power nie gelernt, ich hab noch delphi 6.
|
AW: Delphi Procedure Programm Hilfe
Gehört das nicht so?
Delphi-Quellcode:
power(x,2)
mfg |
AW: Delphi Procedure Programm Hilfe
[edit] Sorry, das y fehlt doch nicht. Ist ja eine globale Variable ...
|
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] |
AW: Delphi Procedure Programm Hilfe
als ergebnis zeigt das panel immer 0
|
AW: Delphi Procedure Programm Hilfe
Wenn x und c null sind stimmt das doch.
|
AW: Delphi Procedure Programm Hilfe
Änder mal testweise das Button-Event so ab:
Delphi-Quellcode:
Wird nun ein Dialog angezeit?
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; Was zeigt der? |
AW: Delphi Procedure Programm Hilfe
Also, bei mir funktioniert der Quelltext. Z.B. 5 in Edit1 und 3 in Edit2 ergibt 53.
|
AW: Delphi Procedure Programm Hilfe
Zitat:
|
AW: Delphi Procedure Programm Hilfe
Und was wird übergeben? (X,C)
Gruß K-H |
AW: Delphi Procedure Programm Hilfe
Zitat:
|
AW: Delphi Procedure Programm Hilfe
X auf 4 und C auf 10 ;)
|
AW: Delphi Procedure Programm Hilfe
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:40 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz