c++ - 如何使用 C++ 在函数中添加 double ?

标签 c++

基本上我在 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/

相关文章:

c++ - 如何从C++代码启动IE并在网页更改后能够获取html数据

c++ - 识别Win32/Win64中的数据段

c++ - 使用 Core foundation 向 Mountain Lion 通知中心发送消息

c++ - 是否可以将 long long 返回值分配给 int64_t 而不会丢失 64 位机器的精度?

ubuntu linux .cpp 中的 c++ 模板

c++ - 散列指针作为 C++ STL 中 unordered_map 的键

c++ - 标准 C++ 中的共享递归互斥锁

c++ - 对在用于实时 IIS 7.0 事件记录的 Visual C++ 代码中使用 'HANDLE' 感到困惑

c++ - 为什么编译器不为模板类提供默认的 operator=?

c++ - 当我可以在main()中编写所有内容时,需要什么 “normal”函数?