Assume personal income 税率×(工资−1600)
tax: . Please write a program to calculate the income tax payable, where the tax rate is defined as:
- When the salary does not exceed
1600
, the tax rate is0
; - When the salary is in the range
(1600, 2500]
, the tax rate is5%
; - When the salary is in the range
(2500, 3500]
, the tax rate is10%
; - When the salary is in the range
(3500, 4500]
, the tax rate is15%
; - When the salary exceeds
4500
, the tax rate is20%
.
Input format:
Enter a non-negative salary in one line.
Output format:
Output personal income tax on one line, accurate to 2 decimal places.
Input example 1:
1600
Output example 1:
0.00
Input example 2:
1601
Output example 2:
0.05
Input example 3:
3000
Output sample 3:
140.00
Input example 4:
4000
Output sample 4:
360.00
Input example 5:
5000
Output sample 5:
680.00
Code:
# include <stdio.h>
# include <stdlib.h>
int main() {
double salary,pay;
scanf("%lf",&salary);
if (salary <= 1600) pay = 0;
else if (salary <= 2500) {
pay = (salary - 1600) * 0.05;
}else if (salary <= 3500) {
pay = (salary - 1600) * 0.1;
}else if (salary <= 4500) {
pay = (salary - 1600) * 0.15;
}else {
pay = (salary - 1600) * 0.2;
}
printf("%.2lf",pay);
return 0;
}
Submit screenshot:
Problem-solving ideas:
It’s just the task of the master (application of the piecewise function~). In fact, this setting is quite unreasonable. I think that each file should be paid according to the tax rate of that file. For example: I have a monthly salary of 4,500 yuan, then I need to pay The cost is:
0 + (2500 - 1600) * 0.05 + (3500 - 2500) * 0.1 + (4500 - 3500) * 0.15 = 295.0