基本上我在 C++ 中设置了我的 double ,由于某种原因它给了我这个错误
"..\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; 番茄=产品添加(番茄); 价格 = 3.02; tomatoprice = addprice(价格); cout << "你有订单"<< tomato << "tomatos."<< 结束; 休息;
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;
最佳答案
因为 total
是函数的名称 - 您不能使用它。使用临时变量或将代码更改为
double total(double appleprice, double pearprice, double tomatoprice)
{
return appleprice + pearprice + tomatoprice;
}
关于c++ - 如何使用 C++ 在函数中添加 double ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40066313/