C ++减法函数相互形成

时间:2014-10-07 21:32:28

标签: c++

我需要弄清楚如何相互减去两个函数的值,基本上使用下面的方法使我的main方法工作。在main方法中,我从用户获取字符,并从用户获取messageUnits的数量,然后将其应用到calculateA函数中。我想从另一个计算值中减去一个函数值。

cout << "Cost savings $" << calculationA('a', units) - calculationA('b', units) << endl;



double calculationA(char a, double messageUnits)
{
    if (a == 'a' || 'A')
    {
        const double constantA = 10.95;
        if (messageUnits > 10)
        {
            double cost = ((messageUnits - 10) * 0.50 + (constantA));
            return cost;
        }
        else if (messageUnits <= 10)
        {
            return constantA;
        }
    }
    else if (a == 'b' || 'B')
    {
        const double constantB = 19.95;
        if (messageUnits > 20)
        {
            double cost = ((messageUnits - 20) * 0.25 + (constantB));
            return cost;
        }
        else if (messageUnits <= 20)
        {
            return constantB;
        }
    }
    else if (a == 'c' || 'C')
    {
        const double constantC = 39.95;
        return constantC;
    }
    else
    {
        //note for myself during debugging
        cout << "Ooops! Something went wrong! " << endl;
    }
}

1 个答案:

答案 0 :(得分:1)

if条件的格式应为(a=='b')||(a=='B')而非a=='b'||'B'