Funktion Addition gibt nicht das Ergebnis aus



  • Hallo liebe Gemeinde.

    Ich habe folgenden Programmcode aufgesetzt:

    #include <iostream>
    using namespace std;
    
    float Add(float x, float y)
    {
    	cout << x << " + " << y << endl;
    	return(x+y);
    }
    
    int main()
    {
    	cout << "Im Main" << endl;
    	cout << endl;
    	float a, b ;
    	cout << "Geben Sie zwei Zahlen eine: " << endl;
    	cin >> a;
    	cin >> b;
    	cout << endl;
    	cout << "Jetzt wird das Ergebnis gezeigt: " << endl;
    	float c = Add(a,b);
    	cout << endl;
    	cout << "Ende im Gelaende!" << endl;
    	cout << endl;
    
    	return 0;
    }
    

    Es wird alles angezeigt. Also ich kann zwei Zahlen eingeben, die in der nächsten Zeile ausgegeben werden.

    Bloß erscheint nicht das Ergebnis wie "c=..." Ich sehe leider den Fehler nicht.

    Gruß Max



  • Sorry Leute, ich weiß den Fehler. Ich poste gleich den richtigen Code.



  • Hier ist der richtige Code:

    #include <iostream>
    using namespace std;
    
    float Add(float x, float y)
    {
    	cout << x << " + " << y << endl;
    	return(x+y);
    }
    
    float Min (float x, float y)
    {
    	cout << x << " - " << y << endl;
    	return (x-y);
    }
    
    float Mul (float x, float y)
    {
    	cout << x << " * " << y << endl;
    	return (x*y);
    }
    
    float Div (float x, float y)
    {
    	cout << x << " / " << y << endl;
    	return (x/y);
    }
    
    int main()
    {
    	cout << "Im Main" << endl;
    	cout << endl;
    	float a, b ;
    	cout << "Geben Sie zwei Zahlen eine: " << endl;
    	cin >> a;
    	cin >> b;
    	cout << endl;
    	cout << "Jetzt werden die Ergebnisse gezeigt: " << endl;
    	cout << endl;
    	float c = Add(a,b);
    	cout << "c wurde gesetzt auf " << c << endl;
    	float d = Min(a,b);
    	cout << "d wurde gesetzt auf " << d << endl;
    	float e = Mul(a,b);
    	cout << "e wurde gesetzt auf " << e << endl;
    	float f = Div(a,b);
    	cout << "f wurde gesetzt auf " << f << endl;
    	cout << endl;
    	cout << "Ende im Gelaende!" << endl;
    	cout << endl;
    
    	return 0;
    }
    

    Zwar habe ich im ersten Code z. B.

    float c = Add(a,b)
    

    gesetzt, aber ich habe vergessen c an sich auch auszugeben.

    Sorry nochmal, dass ich nicht schon eher darauf gekommen bin.

    Gruß

    Max


Anmelden zum Antworten