Skip to content

Instantly share code, notes, and snippets.

@siakaramalegos
Created October 21, 2015 13:33
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 siakaramalegos/b840c2c2d55e40916dd6 to your computer and use it in GitHub Desktop.
Save siakaramalegos/b840c2c2d55e40916dd6 to your computer and use it in GitHub Desktop.
Homework 1.1 Division problem
def division
puts "Give me an integer!"
integer1 = gets.chomp.to_i
puts "Give me another integer!"
integer2 = gets.chomp.to_i
if integer2 == 0
puts "Sorry, can't divide by zero!"
# Instead of just ending the method, we can call it again from inside itself! This is known as recursion.
division
else
result = integer1 / integer2
remainder = integer1 % integer2
"#{integer1} / #{integer2} is #{result} with a remainder of #{remainder}"
end
end
puts division
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment