Forum
Komische Fehlermeldung (Computertechnik)
» Inzwischen habe ich die Fehlermeldung beheben können, dennoch ist ein neues
» Problem aufgetaucht.
»
» Ich wollte zu den Rechenoperationen
» ->+
» ->-
» ->*
» ->/
» ->Wurzl
»
» noch die Potenzfunktion hinzufügen.
»
» Hier der Quellcode:
»
» #include
»
» float Add(float a, float b)
» {
» cout << endl;
» cout << "Addition!" << endl;
» cout << "Zwei Zahlen bitte!" << endl;
» cin >> a >> b;
» float c = a + b;
» cout << a << " + " << b << " = " << c << endl;
» cout << endl;
» return c;
» }
» float Sub(float d, float e)
» {
» cout << endl;
» cout << "Subtraktion!" << endl;
» cout << "Zwei Zahlen bitte!" << endl;
» cin >> d >> e;
» float f = d - e;
» cout << d << " - " << e << " = " << f << endl;
» cout << endl;
» return f;
» }
» float Mul(float g, float h)
» {
» cout << endl;
» cout << "Multiplikation!" << endl;
» cout << "Zwei Zahlen bitte!" << endl;
» cin >> g >> h;
» float i = g*h;
» cout << g << " * " << h << " = " << i << endl;
» cout << endl;
» return i;
» }
» float Div(float j, float k)
» {
» cout << endl;
» cout << "Division!" << endl;
» cout << " Zwei Zahlen bitte, jedoch darf der Zähler nicht 0 sein!" <<
» endl;
» cin >> j >> k;
» float l = j/k ;
» cout << j << " / " << k << " = " << l << endl;
» cout << endl;
» return l;
» }
»
» float Wurzel(float m)
» {
» cout << endl;
» cout << "Quadratwurzel!" << endl;
» cout << "Eine Zahl bitte!" << endl;
» cin >> m;
» float n = sqrt (m);
» cout << "Ergebnis ist " << n << endl;
» cout << endl;
» return n;
» }
» float Potenz(float o, float p)
» {
» cout << endl;
» cout << "Potenz!" << endl;
» cout << "Zwei Zahlen bitte!" << endl;
» cin >> o >> p;
» float q=pow(o,p);
» cout << "Ergebnis ist " << q << endl;
» return q;
» }
»
» int main()
» {
» float a=0,b=0,c=0;
» float d=0,e=0,f=0;
» float g=0,h=0,i=0;
» float j=0,k=0,l=0;
» float m=0,n=0;
» float o=0,p=0,q=0;
»
» cout << "Rechenoperationen!" << endl;
»
» c=Add(a,b);
» f=Sub(d,e);
» i=Mul(g,h);
» l=Div(j,k);
» n=Wurzel(m);
» q=pow(o,p);
» return 0;
» }
»
» Beim Kompilieren kommt keine Fehlermeldung. Bloß beim Starten ohne
» Debugging taucht die Potenzfunktion einfach nicht auf, die Ausgabe hört
» einfach nach der Wurzelfunktion auf zu arbeiten.
»
» Kann mir jemand von euch einen Tipp geben?
»
» Danke für die Antworten im Voraus.
»
» Gruß
»
» Max
Hallo,
deine Funktion heißt Potenz, aufrufen tust du aber pow.
Konzeptionell geht hier aber auch einiges durcheinander: Du deklarierst globale Variablen, die aber nur lokal in den Funktionen verwendet werden. Du gibst das Ergebnis der Berechnung zurück, verwendest es in der Main aber nicht. Besser ist einer der beiden Wege:
1. Du machst die Ein- und Ausgabe wie bisher in den Funktionen selbst, verwendest aber lokale Variablen, sparst Dir also die Parameterübergabe über die Funktion, außerdem auch die Rückgabe, z.B.:
void Add()
{
cout << "Addition!" << endl;
cout << "Zwei Zahlen bitte!" << endl;
float a, b, c;
cin >> a >> b;
float c = a + b;
cout << a << " + " << b << " = " << c << endl;
}
2. Du machst die Ein- und Ausgaben in der Main und nur die Berechnung in den Funktionen:
float Add(float a, float b)
{
return (a + b);
}
float Sub(float a, float b)
{
return (a - b);
}
int main()
{
float a, b, c;
cout << "Addition!" << endl;
cout << "Zwei Zahlen bitte!" << endl;
cin >> a >> b;
c = Add(a, b);
cout << a << " + " << b << " = " << c << endl;
cout << endl;
cout << "Subtraktion!" << endl;
cout << "Zwei Zahlen bitte!" << endl;
cin >> a >> b;
c = Sub(a, b);
cout << a << " - " << b << " = " << c << endl;
return 0;
}
Schöne Grüße,
Björn
Gesamter Thread:
