Skip to content

Instantly share code, notes, and snippets.

@krsmurata
Created June 15, 2010 21:08
Show Gist options
  • Save krsmurata/439737 to your computer and use it in GitHub Desktop.
Save krsmurata/439737 to your computer and use it in GitHub Desktop.
#!/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