Want more features on Pastebin? Sign Up, it's FREE!
Guest

Calculator

By: a guest on Jan 18th, 2013  |  syntax: Ruby  |  size: 0.84 KB  |  views: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. puts "Add, Subtract, Divide, or Multiply?"
  2.  
  3. command = gets.chomp
  4.  
  5. if command == "add"
  6.         puts "Type in the first number, press enter, then type the other num."
  7.         add1 = gets.chomp
  8.         add2 = gets.chomp
  9.         puts add1.to_f + add2.to_f
  10. end
  11.  
  12. if command == "subtract"
  13.         puts "Type in the first number, press enter, then type the other num."
  14.         sub1 = gets.chomp
  15.         sub2 = gets.chomp
  16.         puts sub1.to_f - sub2.to_f
  17. end
  18.  
  19. if command == "divide"
  20.         puts "Type in the first number, press enter, then type the other num."
  21.         div1 = gets.chomp
  22.         div2 = gets.chomp
  23.         puts div1.to_f / div2.to_f
  24. end
  25.  
  26. if command == "multiply"
  27.         puts "Type in the first number, press enter, then type the other num."
  28.         mult1 = gets.chomp
  29.         mult2 = gets.chomp
  30.         puts mult1.to_f * mult2.to_f
  31. end
  32.  
  33. puts "Would you like to calculate again?"
  34.  
  35. command1 = gets.chomp
  36.  
  37. if command1 == "no"
  38. end
clone this paste RAW Paste Data