"if" 语句不符合我的指令 C#

"if" statement does not follow my instructions C#

所以基本上我试图让它解释如果我输入超过 200 马力,速度应该增加 15,这是有效的,如果我输入 "BMW" 那么速度应该增加 10,这不行,我想不通为什么,如果马力小于200且品牌不是宝马,它应该增加5,这也有效。

    public string brand;
    public string model;
    public int hp;
    public int speed = 25;

    public int GetSpeed()
    {
        return this.speed;

    }

    public void SetSpeed(int newspeed)
    {
        if (speed < 0 || speed > 260)
        {
            Console.WriteLine("Please input a valid speed");
        }
        else
        {
            this.speed = newspeed;
        }

    }

    public string GetBrand()
    {
        return this.brand;
    }

    public void SetBrand(string newbrand)
    {
        this.brand = newbrand;
    }

    public string GetModel()
    {
        return this.model;
    }

    public void SetModel(string newmodel)
    {
        this.model = newmodel;
    }

    public int GetHp()
    {
        return this.hp;
    }

    public void SetHp(int newhp)
    {
        this.hp = newhp;
    }

    public int Accelerate(int step = 10, int new_speed = 5, int hpov = 15)
    {
        if (hp >= 200)
        {
            this.speed += hpov;
            if (brand == "BMW")
            {
                this.speed += step;
            }
        }
        else if (brand != "BMW")
        {
            this.speed += new_speed;
        }

        return this.speed;
    }

}

}

这是因为您只有在不是 BMW 的情况下才增加马力,而不是总是增加马力。

public int Accelerate(int step = 10, int new_speed = 5, int hpov = 15)
{
    if (hp >= 200)
    {
        this.speed += hpov;
        if (brand == "BMW")
        {
            this.speed += step;
        }
    }
    else if (brand != "BMW")
    {
        this.speed += new_speed;
    }

    return this.speed;
}

好的,"thanks" 求助,重新制作成这样 ->

 public int Accelerate(int step = 10, int new_speed = 5, int hpov = 15)
    {
        if (hp >= 200)
        {
            this.speed += hpov;

            if (brand == "BMW")
            {
                this.speed += step;
                return this.speed;
            }
            return this.speed;


        }
        else
        {
            this.speed += new_speed;
            return this.speed;

        }

    }

它可以正常工作。