Created
June 15, 2010 21:08
-
-
Save krsmurata/439737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Usage: ruby juros.rb aplicacao_mensal juros meses | |
aplicacao = ARGV[0].to_f | |
juros = ARGV[1].to_f | |
meses = ARGV[2].to_i | |
def calcula_juros(aplicacao, juros, meses) | |
@total = 0.0 | |
for i in 1..meses do | |
rendimento = (@total+aplicacao) * juros/100 | |
@total = (@total + aplicacao) * (1 + juros/100) | |
puts "Mes #{i} # Total: R$ #{@total.round} @ Rendimento: R$ #{rendimento.round}" | |
end | |
return @total | |
end | |
calcula_juros(aplicacao, juros, meses) | |
puts "Aplicacao: R$ #{aplicacao}/mes" | |
puts "Total Aplicado: R$ #{meses*aplicacao}" | |
puts "Juros: #{juros} %" | |
puts "Meses: #{meses}" | |
puts "Ganho em juros: R$ #{@total.round-meses*aplicacao}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment