Search code examples
c++outputdouble

My positive double value is printed as a negative output like -6.27744e+66


I get a negative output to a positive double variable. My object is: Fahrzeug fr("BMW",200.45);

 class Fahrzeug {
    private:
    string p_sName;
        double p_dMaxGeschwindigkeit;
    public:
        Fahrzeug(string p_sName, double p_dMaxgeschwindigkeit) {
            this->p_sName = p_sName; 
            this->p_dMaxGeschwindigkeit = p_dMaxGeschwindigkeit; //the output is negative
            cout << "Der Name des Fahrzeugs: " << this->p_sName << "\n" << "Die maximale Geschwindigkeit des Fahrzeugs: " << this->p_dMaxGeschwindigkeit << endl;
            }
    };
        #endif /* FAHRZEUG_H_*/

Solution

  • this->p_dMaxGeschwindigkeit = p_dMaxGeschwindigkeit; this assigns the (uninitialised) member variable to itself.

    You also have a parameter called p_dMaxgeschwindigkeit which you probably meant to use but note that its not the same spelling - it has a lowercase G and C++ is case sensitive.