Created
October 21, 2015 13:33
-
-
Save siakaramalegos/b840c2c2d55e40916dd6 to your computer and use it in GitHub Desktop.
Homework 1.1 Division problem
This file contains 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 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