Skip to content

Instantly share code, notes, and snippets.

@ramiresnas
Created August 17, 2024 11:57
Show Gist options
  • Save ramiresnas/fe5afee5b73813beff5b47e6fc41176b to your computer and use it in GitHub Desktop.
Save ramiresnas/fe5afee5b73813beff5b47e6fc41176b to your computer and use it in GitHub Desktop.
func calcularImpostoDeRenda(rendaAnual: Double,
dependentes: Int,
despesasMedicas: Double) -> Double {
var imposto = 0.0
if rendaAnual <= 22847.76 {
imposto = 0
} else if rendaAnual <= 33919.80 {
imposto = (rendaAnual - 22847.76) * 0.075
} else if rendaAnual <= 45012.60 {
imposto = (11072.04 0.075) + ((rendaAnual - 33919.80) 0.15)
} else if rendaAnual <= 55976.16 {
imposto = (11072.04 0.075) + (11092.80 0.15) + ((rendaAnual - 45012.60) * 0.225)
} else {
imposto = (11072.04 0.075) + (11092.80 0.15) + (10963.56 0.225) + ((rendaAnual - 55976.16) 0.275)
}
let descontoDependentes = Double(dependentes) * 189.59
let descontoMedico = despesasMedicas
imposto -= descontoDependentes + descontoMedico
return max(imposto, 0) // Imposto não pode ser negativo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment