我正试图让它显示正确的东西。当我运行它时,酒店成本保持在960美元,如果我选择开罗,它将显示机票价格为0美元,而酒店为960美元。其他人都很好,但不会改变酒店价格从$ 960。
if ($destination == "Barcelona")
$airFare = 875;
$hotel = 85 * $numNights;
if ($destination == "Cairo")
$airfare = 950;
$hotel = 98 * $numNights;
if ($destination == "Rome")
$airFare = 875;
$hotel= 110 * $numNights;
if ($destination == "Santiago")
$airFare = 820;
$hotel = 85 * $numNights;
if ($destination == "Tokyo")
$airFare = 1575;
$perNight = 240;
$tickets = $numTravelers * $airFare;
$hotel = $numTravelers * $numNights * $perNight;
$totalCost = $tickets + $hotel;
print("<p>Destination: $destination<br />");
print("Number of people: $numTravelers<br />");
print("Number of nights: $numNights<br />");
print("Airline Tickets: $".number_format($tickets, 2)."<br />");
print("Hotel Charges: $".number_format($hotel, 2)."</p>");
print("<p><strong>TOTAL COST: $".number_format($totalCost, 2)."</strong></p>");
一些问题:
if
带缩进的无括号语句,因此尚不清楚您的意图是什么。为了安全起见:除非大括号if
都在一行上,否则请始终使用大括号!这就是造成苹果今年年初严重的OpenSSL错误的原因。$numNights
是undefined,0
在PHP中默认为undefined 。零的任何乘积就是...零。因此,为什么涉及到您的计算就出错了$numNights
。$
字符嵌入在双引号中的字符串中,这意味着PHP将尝试解析这些字符串以获取变量名。通过使用\$
或使用单引号字符串来转义符号。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句