我有这个代码(http://pastebin.com/aWTsGDFW)当我尝试构建它时我有错误无效操作数二进制表达式('float **'和'float')行“* amount =& amount + productPrice; “在addToAmount操作中。有人帮帮我吗?谢谢!
相关代码粘贴在下面:
void addToAmount (float *amount, float price, int qtt, char promo, float VAT){
float productPrice;
productPrice = 0.0;
if (promo == PROMO_NONE){
productPrice = computeNoPromoPrice(price, qtt, VAT);
}else{
if(promo == PROMO_3x2){
productPrice = computeNxMPromoPrice(3, 2, price, qtt, VAT);
}else{
if(promo == PROMO_2x1){
productPrice = computeNxMPromoPrice(2, 1, price, qtt, VAT);
}else{
productPrice = computeHalfPromoPrice (price, qtt, VAT);
}
}
}
*amount = &amount + productPrice; // <- error here
}
答案 0 :(得分:0)
您正在为float
值添加双float
指针并且没有意义:
*amount = &amount + productPrice;
您应该将该行更改为
*amount += productPrice; // Equivalent to *amount = *amount + productPrice;
而且:你应该在你的问题中正确地格式化代码。
答案 1 :(得分:0)
*amount = &amount + productPrice;
相当于说数量指向的浮点数等于数量的内存地址加上productPrice。
*amount = *amount + productPrice;
似乎是你想要做的事情。