用switch语句计算个人所得税
时间: 2024-05-19 11:08:00 浏览: 247
使用switch语句计算个人所得税可以根据不同的收入范围选择不同的税率进行计算。以下是一个示例代码:
```cpp
#include <iostream>
using namespace std;
int main() {
double income;
cout << "请输入您的收入:";
cin >> income;
double tax = 0.0;
int level;
if (income <= 5000) {
level = 1;
} else if (income <= 8000) {
level = 2;
} else if (income <= 17000) {
level = 3;
} else if (income <= 30000) {
level = 4;
} else {
level = 5;
}
switch (level) {
case 1:
tax = income * 0.03;
break;
case 2:
tax = (income - 5000) * 0.1;
break;
case 3:
tax = (income - 8000) * 0.2 + 300;
break;
case 4:
tax = (income - 17000) * 0.25 + 1300;
break;
case 5:
tax = (income - 30000) * 0.3 + 3800;
break;
default:
cout << "输入的收入无效!" << endl;
return 0;
}
cout << "您需要缴纳的个人所得税为:" << tax << "元" << endl;
return 0;
}
```
这段代码中,我们首先根据收入的不同范围确定所属的税率级别(level),然后使用switch语句根据级别计算相应的个人所得税。最后输出计算结果。
阅读全文