Skip to content

Instantly share code, notes, and snippets.

@ventureproz
Created December 8, 2018 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ventureproz/608132afecd82df3c186b8cb9c43effb to your computer and use it in GitHub Desktop.
Save ventureproz/608132afecd82df3c186b8cb9c43effb to your computer and use it in GitHub Desktop.
Simple Calculator in Ruby
def multiply(num_1, num_2)
num_1.to_f * num_2.to_f
end
def divide(num_1,num_2)
num_1.to_f / num_2.to_f
end
def add(num_1, num_2)
num_1.to_f + num_2.to_f
end
def subtract(num_1, num_2)
num_1.to_f - num_2.to_f
end
def remainder(num_1,num_2)
num_1.to_f % num_2.to_f
end
puts "simple calculator"
25.times { print "-" }
puts
puts "enter first number"
num_1 = gets.chomp
puts "enter the second number"
num_2 = gets.chomp
puts "The first number multiplied by the second number is #{multiply(num_1,num_2)}"
puts
puts "The first number divided by the second number is #{divide(num_1,num_2)}"
puts
puts "The first number added to the second number is #{add(num_1,num_2)}"
puts
puts "The first number minus the second number is #{subtract(num_1,num_2)}"
puts
puts "The remainder of the two numbers diveded together is #{remainder(num_1,num_2)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment