Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Daily Programmer 2 Easy
- # Make a calculator, but make it specific to you.
- def interest(a, b, c)
- sum = a.to_i * (b.to_i/100.0) * c.to_i
- total = sum + a.to_i
- puts "The interest on your investment is $#{sum}"
- puts "The total in the account is $#{total}"
- end
- print <<MENU
- This is an interest calculator. It takes your initial investment,
- your interest rate, and your length of the investment to then calculate
- the interest and the total you will have at the end of the period.
- Please enter a choice from the menu:
- '1' > Calculate interest!
- '2' > Quit
- MENU
- choice = gets.chomp
- while (choice == '1' && choice != '2')
- puts "Please enter a starting investment (using a decimal since it's a monetary value, eg. 4000.00): "
- STDOUT.flush
- initial = gets.chomp
- puts "Please enter an interest rate as a percentage (20% = 20, 0.9% = 0.9, etc.): "
- STDOUT.flush
- rate = gets.chomp
- puts "Please enter an amount of time in months: "
- STDOUT.flush
- duration = gets.chomp
- interest(initial, rate, duration)
- puts "Shall you make another choice? "
- choice = gets.chomp
- end
- puts "Thank you for using the interest calculator."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement