LoginSignup
0
0

More than 3 years have passed since last update.

ローン/リボ払い/返済シュミレータ/Ruby

Last updated at Posted at 2019-07-16

ローン、リボ払いのシミュレータをrubyで作ってみた
コメントで補足もつけているためコードを参照されたし。

ご利用は計画的に.rb
puts "借入額を入力してください"
borrow_money = gets.to_f
puts "月々の返済額を入力してください"
monthly_pay_money = gets.to_f
puts "年利を複利計算(%)で入力してください"
interest_rate = gets.to_f / 100 + 1 # 年利を入力
monthly_interest_rate = interest_rate**(1.0/12.0) # 月利に変換

pay_month,pay_money = 0,0

while borrow_money > 0
  borrow_money -= monthly_pay_money
  borrow_money *= monthly_interest_rate # 月利を複利で計算
  pay_month += 1
  pay_money += monthly_pay_money # 現状返済額は最後の月まで一定で仮定しているため若干ずれるが、月々の支払いが大き過ぎない限りあまり問題はない
end

puts "ーーーーーーーーーーーーーーー"
puts "返済期間は#{pay_month/12}#{pay_month%12}ヶ月、合計返済額は#{pay_money}円です"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0