Fehler mit Winkelfunktion
-
hallo,
habe folgendes objekt programmiert.
compilieren funktioniert
wenn ich auf run klicke kommt folgender fehler:http://www.bilder-space.de/show.php?file=WsLps77dY13csLG.PNG
mfg
ps: debugger hilft mir auch nicht weiter
-
//--------------------------------------------------------------------------- #include <vcl.h> #include <math.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- double sin(double x); double cos(double x); double tan(double x); #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { double winkel,erg; winkel=StrToFloat(Edit1->Text); if(RadioGroup1->ItemIndex==0) erg=sin(winkel); if(RadioGroup1->ItemIndex==1) erg=cos(winkel); if(RadioGroup1->ItemIndex==2) erg=tan(winkel); Edit2->Text=FloatToStr(erg); } //---------------------------------------------------------------------------
-
Was passiert denn, wenn Du die Forwarddeklarationen entfernst? Ausserdem kannst Du cmath statt Math.h einbinden.
-
erg und winkel sind doch doubles. Wieso nimmst du dafür StrToInt und Konsorten und nicht StrToFloat etc.?
-
witte schrieb:
Was passiert denn, wenn Du die Forwarddeklarationen entfernst? Ausserdem kannst Du cmath statt Math.h einbinden.
cmath oder math.h is ja egal
-
Braunstein schrieb:
erg und winkel sind doch doubles. Wieso nimmst du dafür StrToInt und Konsorten und nicht StrToFloat etc.?
danke, da hast du recht, aber das is nicht die lösung des problems
http://www.bilder-space.de/show.php?file=747XLiPDnW9ULHv.PNG
mfg
-
bist du zufällig auf einem 64-bit system?
-
nein, bin ich nicht.
-
Wie witte schon sagte, wirf die Forwarddeklarationen deiner Winkelfunktionen raus.
das hierdouble sin(double x); double cos(double x); double tan(double x);
Wenn du cmath einbindest muss vor jede dieser Funktionen dann noch ein std::
//--------------------------------------------------------------------------- #include <vcl.h> #include <cmath> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { double winkel,erg; winkel=StrToFloat(Edit1->Text); if(RadioGroup1->ItemIndex==0) erg=std::sin(winkel); if(RadioGroup1->ItemIndex==1) erg=std::cos(winkel); if(RadioGroup1->ItemIndex==2) erg=std::tan(winkel); Edit2->Text=FloatToStr(erg); } //---------------------------
-
es soll praktisch ausgewählt werden, welcher typ (sin,cos,tan) berechnet werden soll
in edit1 ist der winkel, in edit2 das ergebnis
-
danke @ braunstein und witte, so funktioniert es
danke für die schnelle hilfe