private static double CalcTax(double salary)
{
double C0 = 3000, C0Ratio = 0.00;
int L1 = 1500, L2 = 4500, L3 = 9000, L4 = 35000, L5 = 55000, L6 = 80000;
double C1 = L1-0, C1Ratio = 0.05;
double C2 = L2-L1, C2Ratio = 0.10;
double C3 = L3-L2, C3Ratio = 0.20;
double C4 = L4 - L3, C4Ratio = 0.25;
double C5 = L5 - L4, C5Ratio = 0.30;
double C6 = L6 - L5, C6Ratio = 0.35;
double C7 = double.MaxValue, C7Ratio = 0.45;
double minValue = 0.0;
double deltValue = salary;
double tax = 0;
if (salary <= 0) return 0;
minValue = Math.Min(salary, C0); tax += minValue * C0Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level1
minValue = Math.Min(deltValue, C1); tax += minValue * C1Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level2
minValue = Math.Min(deltValue, C2); tax += minValue * C2Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level3
minValue = Math.Min(deltValue, C3); tax += minValue * C3Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level4
minValue = Math.Min(deltValue, C4); tax += minValue * C4Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level5
minValue = Math.Min(deltValue, C5); tax += minValue * C5Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level6
minValue = Math.Min(deltValue, C6); tax += minValue * C6Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level7
minValue = Math.Min(deltValue, C7); tax += minValue * C7Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
return tax;
}
{
double C0 = 3000, C0Ratio = 0.00;
int L1 = 1500, L2 = 4500, L3 = 9000, L4 = 35000, L5 = 55000, L6 = 80000;
double C1 = L1-0, C1Ratio = 0.05;
double C2 = L2-L1, C2Ratio = 0.10;
double C3 = L3-L2, C3Ratio = 0.20;
double C4 = L4 - L3, C4Ratio = 0.25;
double C5 = L5 - L4, C5Ratio = 0.30;
double C6 = L6 - L5, C6Ratio = 0.35;
double C7 = double.MaxValue, C7Ratio = 0.45;
double minValue = 0.0;
double deltValue = salary;
double tax = 0;
if (salary <= 0) return 0;
minValue = Math.Min(salary, C0); tax += minValue * C0Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level1
minValue = Math.Min(deltValue, C1); tax += minValue * C1Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level2
minValue = Math.Min(deltValue, C2); tax += minValue * C2Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level3
minValue = Math.Min(deltValue, C3); tax += minValue * C3Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level4
minValue = Math.Min(deltValue, C4); tax += minValue * C4Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level5
minValue = Math.Min(deltValue, C5); tax += minValue * C5Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level6
minValue = Math.Min(deltValue, C6); tax += minValue * C6Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
//level7
minValue = Math.Min(deltValue, C7); tax += minValue * C7Ratio;
deltValue -= minValue; if (deltValue == 0) return tax;
return tax;
}