samedi 22 octobre 2016

Why can this code not return the bpEffect variable with the value 505.5?

The expected result from the following code should be 505.5, but instead it returns 3.97541e+70. Why is this the case and how can the problem be solved ?

#include <iostream>
#include <string>
using namespace std;
class Position {
public:
    Position(int s, double p, string n) {
        shares = s;
        price = p;
        name = n;
    }
    double getBpEffect() {
        return bpEffect;
    }
private:
    string name;
    int shares;
    double price;
    double bpEffect = (shares*price) / 2;

};


int main() {
    Position xyz = Position(100, 10.11, "xyz");
    double buyingPower = xyz.getBpEffect();


    cout << buyingPower;

    system("pause");
    return 0;

}

Aucun commentaire:

Enregistrer un commentaire