Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading