Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Calculator
#ruby 2.3.1 class Calc def sum(a,b) puts "Sum is #{a+b} " end def subs(a,b) puts "Difference is #{a-b} " end def multi(a,b) puts "Product is #{a*b} " end def div(a,b) puts "Quotient is #{a/b} " end def pow(a,b) puts "Result is #{a**b} " end end M=Calc.new puts "1. Add" puts "2. Subtract" puts "3. Multiply" puts "4. Division" puts "5. Power" puts "6. Exit" puts "Select any one:" n=gets.to_i puts n case n when 1 a=gets.to_f b=gets.to_f M.sum(a,b) when 2 a=gets.to_f b=gets.to_f M.subs(a,b) when 3 a=gets.to_f b=gets.to_f M.multi(a,b) when 4 a=gets.to_f b=gets.to_f M.div(a,b) when 5 a=gets.to_f b=gets.to_f M.pow(a,b) else puts "No match found!!!" puts "End" end
run
|
edit
|
history
|
help
0
piramid4
regex.rb
boolean
yes
ElaineBrown** rextester.com
Arithmetic Operations, Function Calls, Recursion and more in Ruby
string orperations lecture and print
MACK FIRST wall
Adiel Vasquez
ruby LRU cache with constant get/set