1
0
Fork 0
57-ruby-exercises/012_computing_simple_intere...

14 lines
473 B
Ruby

# 012_computing_simple_interest
def calculate_interest_with(principal, rate, num_years)
principal * (rate * num_years)
end
puts("Enter the principal amount: ")
principal = gets.chomp.to_f
puts("Enter the rate of interest, in %:")
interest = gets.chomp.to_f / 100
puts("Enter the number of years:")
years = gets.chomp.to_i
puts("After #{years} years, at #{interest}%, your investment will be worth #{principal + calculate_interest_with(principal, interest, years)}")