C++ 在IF函数中查找加减法

C++ 在IF函数中查找加减法,c++,if-statement,math,C++,If Statement,Math,所以,也许我很笨(好吧,这与问题无关,因为我是),但我正在尝试在“If语句”中加减值。 到目前为止没有崩溃,但也没有增加或减少 代码如下: cout << "Let's spend some Skill Points..." << endl; cout << "Strength(Str):"; cin >> UserInputSP; if(UserInputSP <= Playe

所以,也许我很笨(好吧,这与问题无关,因为我是),但我正在尝试在“If语句”中加减值。 到目前为止没有崩溃,但也没有增加或减少

代码如下:

cout << "Let's spend some Skill Points..." << endl;
    cout << "Strength(Str):";
    cin >> UserInputSP;
    if(UserInputSP <= Player.SP && UserInputSP > 0){
        Player.Str + UserInputSP;
        Player.SP - UserInputSP;
        UserInputSP = 0;
        cout << "Skill Points: " << Player.SP << endl;
    } else {
        cout << "You don't have enough Skill Points!" << endl;

cout如果我理解你的代码,这些行计算你想要的新值,但不做任何事情

Player.Str + UserInputSP;
Player.SP - UserInputSP;
我想你想要的是复合赋值运算符:

Player.Str += UserInputSP;
Player.SP -= UserInputSP;
这等于说:

Player.Str = Player.Str + UserInputSP;
Player.SP = Player.SP - UserInputSP;

请不要张贴代码的图片。将相关代码粘贴到问题中。注意:逗号运算符不同于AND
&&
运算符
if(A,B)
if(B)
相同。