次のコードの期待される結果は 505.5 ですが、代わりに 3.97541e+70 が返されます。これはなぜですか?また、どのように問題を解決できますか?
#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;
}