Created
December 8, 2018 01:19
-
-
Save ventureproz/608132afecd82df3c186b8cb9c43effb to your computer and use it in GitHub Desktop.
Simple Calculator in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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