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;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…