循环计算价格
Loop to Calculate Price
试图创建一个循环来计算价格,但我不知道该怎么做。
$sell = ($price*$vat);
$profit = ((($price*$vat)*0.04)+0.2);
function newSell($price1){
$price1 = $price1 + 0.10;
return $price;
}
do {
$price1 = newSell($price);
$profit = ((($price1*$vat)*0.04)+0.2);
} while ($profit < 0);
$price 是我的商品价格
$sell 是我的起拍价。
$profit 是计算我的利润的计算。
我想做的是环顾四周,如果我的利润小于 0,我想在我的价格上加 10p (0.10),然后重新计算我的利润并再次评估。想要继续前进,直到我的利润高于 1,此时它停止并且我的新销售价格已经设定。
我这辈子都想不通!
非常感谢
首先,您的 newSell 函数应该如下所示:
function newSell($price) {
return $price + .1
}
它目前什么都不做。
其次,您确定这是您应该尝试解决的方法吗?在我看来,您只是想求解 $profit >= 1。这是一个简单的方程式,没有任何循环。
看起来$profit = $price * $vat * .04 + .2
,所以你真的在看1 <= $price * $vat * .04 + .2
或20 / $vat <= $price
所以如果 $price >= 20 / $vat
那么 $profit >= 1
.
具体执行您的要求:
do {
$profit = $price * $vat * .04 + .2;
$price = $price + .1;
} while ($profit < 1);
试图创建一个循环来计算价格,但我不知道该怎么做。
$sell = ($price*$vat);
$profit = ((($price*$vat)*0.04)+0.2);
function newSell($price1){
$price1 = $price1 + 0.10;
return $price;
}
do {
$price1 = newSell($price);
$profit = ((($price1*$vat)*0.04)+0.2);
} while ($profit < 0);
$price 是我的商品价格
$sell 是我的起拍价。
$profit 是计算我的利润的计算。
我想做的是环顾四周,如果我的利润小于 0,我想在我的价格上加 10p (0.10),然后重新计算我的利润并再次评估。想要继续前进,直到我的利润高于 1,此时它停止并且我的新销售价格已经设定。
我这辈子都想不通!
非常感谢
首先,您的 newSell 函数应该如下所示:
function newSell($price) {
return $price + .1
}
它目前什么都不做。
其次,您确定这是您应该尝试解决的方法吗?在我看来,您只是想求解 $profit >= 1。这是一个简单的方程式,没有任何循环。
看起来$profit = $price * $vat * .04 + .2
,所以你真的在看1 <= $price * $vat * .04 + .2
或20 / $vat <= $price
所以如果 $price >= 20 / $vat
那么 $profit >= 1
.
具体执行您的要求:
do {
$profit = $price * $vat * .04 + .2;
$price = $price + .1;
} while ($profit < 1);