Guest User

Untitled

a guest
Jun 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. puts "借入額を入力してください"
  2. borrow_money = gets.to_f
  3. first_borrow_money=borrow_money
  4. puts "月々の返済額を入力してください"
  5. monthly_pay_money = gets.to_f
  6. puts "年利を複利計算(%)で入力してください"
  7. interest_rate = gets.to_f / 100 + 1 # 年利を入力
  8. monthly_interest_rate = interest_rate**(1.0/12.0) # 月利に変換
  9.  
  10. pay_month,pay_money = 0,0
  11.  
  12. while borrow_money > 0
  13. borrow_money -= monthly_pay_money
  14. borrow_money *= monthly_interest_rate # 月利を複利で計算
  15. pay_month += 1
  16. pay_money += monthly_pay_money # 現状返済額は最後の月まで一定で仮定しているため若干ずれるが、月々の支払いが大き過ぎない限りあまり問題はない
  17. end
  18.  
  19. puts "ーーーーーーーーーーーーーーー"
  20. puts "返済期間は#{pay_month/12}年#{pay_month%12}ヶ月、合計返済額は#{pay_money}円です"
Add Comment
Please, Sign In to add comment