Anfäger - Unterprogramm
-
Hallo,
ich bin noch recht neu, was das Programmieren angeht..
Folgendes, sehr einfache Unterprogramm, soll zwei Zahlen aus je einem Editfeld miteinander multiplizieren, und in einem Label anzeigen://---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 Form1;
float a,b,x,y,m;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent Owner)
: TForm(Owner)
{
}//---------------------------------------------------------------------------
void multipliziere()
{
float multipliziere (float a, float b);return a*b ;
}//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
x = StrToFloat(Edit1->Text);
y = StrToFloat(Edit2->Text);
m = multipliziere (x,y);
Label1->Caption = FloatToStr(m);}
//---------------------------------------------------------------------------Gibt aber den Fehler:
[C++ Fehler] Unit1.cpp(25): E2467 'multipliziere()' kann keinen Wert zurückgeben.Was mache ich da falsch?
Vielen Dank schonmal,
Pollux
-
Deine Funktion multipliziere() ist eine void, und kann somit nichts zurückgeben. Einfach anstatt von void float verwenden, dann müsste es klappen!
float multipliziere(float a, float b) { return a*b; }
-
Dankeschön.. Klappt..