php - 如何根据天数降低租金成本
问题描述
有没有一种快速的方法可以根据天数降低租金?
例如:
If I rent a car for 1day, the cost is 100$
If I rent a car for 2days, the cost is 100$ + 70$ = 170$
If I rent a car for 3days, the cost is 100$ + 70$ + 50$ = 220$
If I rent a car for 4days, the cost is 100$ + 70$ + 50$ + 50$ = 270$
If I rent a car for 5days, the cost is 100$ + 70$ + 50$ + 50$ + 50$ = 320$
所以我需要一种快速的方法来根据天数获得总成本。例如:
function getcost(days){
...
return $cost;
}
echo getcost(1); // it show 100$
echo getcost(3); // it show 220$
// and so on...
解决方案
假设从第三天开始,所有连续天都花费 50 美元:
function getcost(int $days) {
return ($days > 1) ? (($days - 2) * 50 + 170) : (($days == 1) ? 100 : 0);
}
推荐阅读
- devops - gitlab-runner 的目的是什么
- vue.js - 从 vue2-daterange-picker 的下拉列表中选择年份
- api - 以编程方式访问谷歌搜索监视列表
- amazon-web-services - org.neo4j.driver.v1.exceptions.ClientException:没有为此数据库实例注册名为“apoc.create.setProperties”的过程
- dns - 无法将流量从 DDNS 服务器转发到我的本地计算机端口
- python-3.x - 编辑:Pyspark:基于另一个数据框删除行,条件多列
- javascript - 在反应中使用发布订阅使组件卸载和安装
- angular - 如何在 ag-grid 中为数字右对齐文本
- php - 无法访问文件:2020-09-25 08:56:12 CLIENT -> SERVER: EHLO
- django - 通过 Django 发送电子邮件时出现无效的电子邮件地址错误