如何在c ++函数中添加双精度?

时间:2016-10-16 02:47:00

标签: c++

基本上我用c ++设置了我的双打,由于某种原因它给了我这个错误

“.. \ project2_name.cpp:56:9:错误:赋值函数'double total(double,double,double)'”。

double appleprice=0;
double pearprice=0;
double tomatoprice=0;
double completetotal=0;


double total(double appleprice, double pearprice, double tomatoprice)
{
    total = appleprice + pearprice + tomatoprice;
        return total;
}

我有一个开关盒,可以从一个除了总数之外的菜单中调用它:     案例'3':             COUT<< “你添加了一个番茄”<< ENDL;             番茄= productsadd(番茄);             价格= 3.02;             tomatoprice = addprice(price);             cout<< “你有订单”<<番茄<< “西红柿。” << ENDL;             打破;

    case '4':
        cout<< "Your Full order" << endl;
        completetotal = total(appleprice, pearprice, tomatoprice);
        cout << "You have on order " << apple << " apples. " << appleprice << " price."<< endl;
        cout << "You have on order " << pear << " pears. " << pearprice << " price."<< endl;
        cout << "You have on order " << tomato << " tomatos. " << tomatoprice << " price."<< endl;
        cout << "You have a total of " << completetotal << endl;
        break;

1 个答案:

答案 0 :(得分:4)

由于total是函数的名称 - 您不能使用它。使用临时变量或者可能将代码更改为

double total(double appleprice, double pearprice, double tomatoprice)
{
    return appleprice + pearprice + tomatoprice;
}