Advertisement
Guest User

Untitled

a guest
Feb 28th, 2012
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.18 KB | None | 0 0
  1. # Daily Programmer 2 Easy
  2. # Make a calculator, but make it specific to you.
  3.  
  4. def interest(a, b, c)
  5.   sum = a.to_i * (b.to_i/100.0) * c.to_i
  6.   total = sum + a.to_i
  7.  
  8.   puts "The interest on your investment is $#{sum}"
  9.   puts "The total in the account is $#{total}"
  10. end
  11.  
  12. print <<MENU
  13.   This is an interest calculator. It takes your initial investment,
  14.   your interest rate, and your length of the investment to then calculate
  15.   the interest and the total you will have at the end of the period.
  16.  
  17.   Please enter a choice from the menu:
  18.   '1' > Calculate interest!
  19.   '2' > Quit
  20. MENU
  21.  
  22. choice = gets.chomp
  23.  
  24. while (choice == '1' && choice != '2')
  25.   puts "Please enter a starting investment (using a decimal since it's a monetary value, eg. 4000.00): "
  26.   STDOUT.flush
  27.   initial = gets.chomp
  28.  
  29.   puts "Please enter an interest rate as a percentage (20% = 20, 0.9% = 0.9, etc.): "
  30.   STDOUT.flush
  31.   rate = gets.chomp
  32.  
  33.   puts "Please enter an amount of time in months: "
  34.   STDOUT.flush
  35.   duration = gets.chomp
  36.  
  37.   interest(initial, rate, duration)
  38.  
  39.   puts "Shall you make another choice? "
  40.   choice = gets.chomp
  41. end
  42.  
  43.  
  44. puts "Thank you for using the interest calculator."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement