创建一个PHP程序利用if-else写利润提成
时间: 2023-12-28 11:03:51 浏览: 30
的计算,可以吗?
当然可以。以下是一个示例程序:
```
<?php
$sales = 10000; // 销售额
$rate = 0; // 提成率
if ($sales <= 1000) {
$rate = 0.05;
} else if ($sales <= 5000) {
$rate = 0.1;
} else if ($sales <= 10000) {
$rate = 0.15;
} else {
$rate = 0.2;
}
$commission = $sales * $rate;
echo "销售额:".$sales."\n";
echo "提成率:".$rate."\n";
echo "提成金额:".$commission."\n";
?>
```
这个程序根据销售额的不同,计算出不同的提成率和提成金额。如果销售额在1000元以下,提成率为5%;在1000元到5000元之间,提成率为10%;在5000元到10000元之间,提成率为15%;超过10000元,提成率为20%。
相关问题
用if-else if-else写判断季节的代码
当然可以!以下是用 if-else if-else 语句来判断季节的示例代码:
```csharp
int month = 10;
string season;
if (month >= 3 && month <= 5)
{
season = "春季";
}
else if (month >= 6 && month <= 8)
{
season = "夏季";
}
else if (month >= 9 && month <= 11)
{
season = "秋季";
}
else
{
season = "冬季";
}
Console.WriteLine("当前季节是:" + season);
```
在上面的代码中,我们使用了一个整型变量 `month` 来表示月份。根据月份的范围,我们使用 if-else if-else 语句来判断当前的季节,并将结果赋值给字符串变量 `season`。最后,我们使用 `Console.WriteLine` 方法来输出当前的季节。
请注意,上述代码只是一个示例,实际应用中可能需要根据具体情况进行调整。
写一个用if- else语句和switch语句计算税金的c++程序
以下是用if-else语句和switch语句计算税金的C程序:
使用if-else语句:
#include <stdio.h>
int main() {
float income, tax;
printf("请输入您的收入:");
scanf("%f", &income);
if (income <= 0) {
printf("您输入的收入不合法!\n");
} else if (income <= 5000) {
tax = 0;
} else if (income <= 10000) {
tax = (income - 5000) * 0.05;
} else if (income <= 20000) {
tax = 250 + (income - 10000) * 0.1;
} else if (income <= 40000) {
tax = 1250 + (income - 20000) * 0.15;
} else if (income <= 60000) {
tax = 3750 + (income - 40000) * 0.2;
} else if (income <= 80000) {
tax = 7750 + (income - 60000) * 0.25;
} else {
tax = 14750 + (income - 80000) * 0.3;
}
printf("您应缴纳的税金为:%.2f元\n", tax);
return 0;
}
使用switch语句:
#include <stdio.h>
int main() {
float income, tax;
printf("请输入您的收入:");
scanf("%f", &income);
if (income <= 0) {
printf("您输入的收入不合法!\n");
} else {
switch ((int)income / 10000) {
case 0:
tax = 0;
break;
case 1:
tax = (income - 5000) * 0.05;
break;
case 2:
case 3:
tax = 250 + (income - 10000) * 0.1;
break;
case 4:
case 5:
tax = 1250 + (income - 20000) * 0.15;
break;
case 6:
case 7:
tax = 3750 + (income - 40000) * 0.2;
break;
default:
tax = 7750 + (income - 60000) * 0.25;
break;
}
printf("您应缴纳的税金为:%.2f元\n", tax);
}
return 0;
}
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)