Forum
Funktionen in C++ (Elektronik)
Hallo liebe Gemeinde.
Seit ca. drei Wochen beschäftige ich mich nun mit Funktionen.
Ich verstehe im Moment nicht, wann man im Funktionskopf Variablen als Parameter übergibt und wann nicht.
Dazu ein Beispiel:
Wenn ich folgenden Quellcode
#include
using namespace std;
void Elvis ()
{
cout << endl;
cout << "Wie alt ist Elvis, unser Hund?" << endl;
cout << "Elvis ist 19 Monate alt!" << endl;
cout << endl;
}
double Division(double , double )
{
cout << "Funktion Division" << endl;
double z = x / y;
return z;
}
int main()
{
cout << endl;
cout << "Verwendung von Funktionen!" << endl;
cout << endl;
Elvis(); //Aufruf der Funktion Elvis
cout << "Zwei Zahlen bitte!" << endl;
double x, y, z;
cin >> x >> y;
z=Division(x,y); //Aufruf der Funktion Division
cout << "z nach Division: " << z << endl;
return 0;
}
debugge, kommt folgende Fehlermeldung:

Wenn ich die beiden Variablen x und y in der Funktion Division deklarire und initialisier, bekomme ich folgende Fehlermeldung:

Erst wenn ich die beiden Variablen im Funktionskopf deklariere wie folgt:
double Division(double x, double y)
{
cout << "Funktion Division" << endl;
double z = x / y;
return z;
}
kommt folgende Ausgabe:

Warum ist das so???? Ich komme einfach nicht drauf.
Vielen Dank für die Antworten im Voraus.
Gruß
Max
P.S.: Hier ist ein Link, bei dem man den Code besser lesen kann:
http://www.c-plusplus.de/forum/p2203987#2203987
--
Where is the madness ...
Gesamter Thread:
