ruby - Ruby:组合 if 语句:为什么我的代码总是打印相同的值?(例如:累进税制)
问题描述
我很糟糕,但出于实际原因我需要这个:为什么当“revenus”优于 15000 时我的代码总是打印“2500”?
这是关于累进税制的:我们给他一份收入,他给我们我们必须缴纳的税款。第 1 级:15 001 欧元以下不征收任何税款(不包括在内)。等级 2:15 001 至 4000 欧元(包括)之间的 10% 税。等级 3:40 001 至 80 000 欧元(含)之间的 15% 税。等级 3 税 25% 超过 80 000 欧元(不包括在内)。
由于 if 语句的组合,这可能是一些愚蠢的语法错误,如果您看到一些明显的错误,请告诉我。
revenus = 17305
copyrevenus = 17305
impots = 0
taux1 = 0/100
taux2 = 10/100
taux3 = 15/100
taux4 = 25/100
full1 = 0 #When the first scale is fully filled (superior or equal to the scale's max amount) i don't bother with multiplication, so this is for 15 000 * taux1 etc.
full2 = 2500
full3 = 6000
if copyrevenus > 15000
impots += full1
revenus - 15000
if copyrevenus > 40000
impots += full2
revenus - 25000
if copyrevenus > 80000
impots += full3
revenus - 40000
impots += revenus * taux4
else
impots += revenus * taux3
end
else
impots += revenus * taux2
end
else
impots = revenus * taux1
end
puts impots
解决方案
Fravadona 和 mu 的回答太短:我修复了除法以使结果浮动,并且我的减法没有为“revenus”分配任何值,所以现在它已修复。
revenus = (write the amount)
fixrevenus = revenus
impots = 0
taux1 = 0.0/100.0
taux2 = 10.0/100.0
taux3 = 15.0/100.0
taux4 = 25.0/100.0
full1 = 0
full2 = 2500
full3 = 6000
if fixrevenus > 15000
impots += full1
revenus -= 15000
if fixrevenus > 40000
impots += full2
revenus -= 25000
if fixrevenus > 80000
impots += full3
revenus -= 40000
impots += revenus * taux4
else
impots += revenus * taux3
end
else
impots += revenus * taux2
end
else
impots += revenus * taux1
end
puts impots
推荐阅读
- python - 在 python 数组中找到由 1 和 0 组成的 1s 组的中点的最佳方法是什么?
- flutter - Flutter 错误:如何将一个小部件类的数据传递给另一个普通类?
- javascript - 更新有关嵌套数组大小的字段
- android - 如何使用 Moshi 处理不同的响应?
- hibernate - Hibernate:子嵌入式实体在合并时得到更新而没有任何更改
- c# - WPF 窗口小于 XAML 中定义的窗口
- reactjs - 带有 react-native 测试库的样式化组件主题
- html-lists - UL LI 怎么去掉padding?
- python - 小幅度向量的数值稳定归一化
- php - Apache NetBeans 12.3 和 XAMPP 3.2.4 PHP 断点 Windows 10