Funktion selber geschrieben, aber funktioniert nicht :(
-
Und auch sicher, dass die Funktion in main stehen soll? Dort werden die nämlich eigentlich nicht definiert.
-
Naja, du solltest funktion außerhalb von main definieren, das kann so doch nicht gehen...
Außerdem heißt es include <iostream>
using namespace std;
Und, du musst innerhalb der Funktion natürlich die namen benutzen, die in der Parameterliste stehen...
-
Ja das habe ich auch gehört, dass man das außerhalb von main machen sollte..
Gut soweit, aber jetzt habe ich noch einen einzigen Error irgendwo...#include <iostream> #include <conio.h> // Windowskonform entfällt bei Unix und Beos Systemen using namespace std; long double funktion(long double funcion, long double funcion2); int main() { double funktionswert1, funktionswert2; cout << "Gib 2 Werte ein" << endl; cin >>funktionswert1; cin >>funktionswert2; long double funktion(long double funcion, long double funcion2) { // Syntax Error before token { und if (funcion >= funcion2) { return funcion; }else return funcion2; // Überprüfung des Programmes } getch(); // Windowskonform entfällt bei Unix und Beos Systemen // Iso C++ forbids getch with no type }
-
So sieht's doch ganz gut aus:
[cpp]
#include <iostream>
#include <conio.h>using namespace std;
long double funktion(long double, long double);
int main(int argc, char **argv) {
double funktionswert1, funktionswert2, erg;cout << "Gib 2 Werte ein" << endl;
cin >>funktionswert1;
cin >>funktionswert2;erg = funktion(funktionswert1, funktionswert2);
cin.get();
return 0; //Edit: hab return 0 vergessen, damn
}long double funktion(long double funcion, long double funcion2) {
if (funcion >= funcion2)
return funcion;
else
return funcion2;
}[/cpp]
-
Und nochmal zu deinem letzten Fehler:
(Wie bereits von vivande gesagt und von GPC geschrieben)
Du darfst keine Funktionen innerhalb von Funktionen definieren!Caipi
-
Heheh gut aber das verstehe ich nicht... Also absolut keine Ahnung wie das da funktioniert. Wie auch immer muss ja quasi nur noch wissen wo da der Fehler im Funktionsaufruf ist und mehr ja nicht...
#include <iostream> #include <conio.h> // Windowskonform entfällt bei Unix und Beos Systemen using namespace std; long double funktion(long double, long double); int main() { long double funktionswert1, funktionswert2; do { cout << "Gib 2 Werte ein" << endl; cin >>funktionswert1; cin >>funktionswert2; long double funktion ( long double funcion, long double funcion2) // Wo liegt da der Hase im Pfeffer ? { if (funcion >= funcion2) return funcion; else return funcion2; } }while( funktionswert <= 0 ) //getch(); // Windowskonform entfällt bei Unix und Beos Systemen }
-
wenn dus nicht kapierst dann zieh dir ein tut rein. und zumletzten mal: int main() ist eine FUNKTION. du deklarierst eine FUNKTION (long double funktion) in der FUNKTION int main!!! Kapiert!!
#include <iostream> #include <conio.h> // Windowskonform entfällt bei Unix und Beos Systemen using namespace std; long double funktion(long double, long double); int main() { long double funktionswert1, funktionswert2; do { cout << "Gib 2 Werte ein" << endl; cin >>funktionswert1; cin >>funktionswert2; } while(funktionswert1<=0&&funkrionswert2<=0); getch(); // Windowskonform entfällt bei Unix und Beos Systemen return 0; } long double funktion(long double function,long double function2) { if(function>=function2) return function; else return function2; }
...
so müssts gehen
-
#include <conio.h> = C
#include <cstdio> = C++Bei c++ gibt es keinen Suffix mehr in den HeaderDateien, (in dem Fall das .h)
du solltest bei c++ immer nur den Namen der Datei schreiben.
Da es unter c++ keine conio mehr gibt nimmt man cstdio
(verbessert mich wenn das nicht stimmt)es gibt noch ein paar Header-Dateien bei denen man darauf achten muss das die Namen stimmen.
z.B: <time.h> = <ctime>
Eine Funktion in einer Funktion ist bei c++ einfach nicht erlaubt
Es gibt aber auch Sprachen die solches unterstützen.Searence
-
du kannst cstdio nicht mit conio.h vergleichen.. cstdio gehört zum C++ standard und conio.h nicht. deswegen c und kein .h hinten. und außerdem hat ihm das nix gebracht ^^
-
Du könntest
..... inline long double funktion(long double, long double); ....
schreiben.
Dann generiert der Compiler das was du dort vorhattest.