Created
March 27, 2013 00:16
-
-
Save tensiondriven/5250517 to your computer and use it in GitHub Desktop.
name.rb
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 display_to_hundred | |
# range: | |
# print (1..100).to_a | |
# n = 0 | |
# 100.times do | |
# n += 1 | |
# puts n | |
# end | |
n = 0 | |
while n < 100 | |
n += 1 | |
puts n | |
end | |
end | |
def display_multiples_of_seven(upto) | |
# n = 0 | |
# upto.times do | |
# n += 1 | |
# if n % 7 == 0 | |
# print n | |
# end | |
# end | |
# n = 0 | |
# while n < upto | |
# n += 1 | |
# if n % 7 == 0 | |
# #print "#{n}\n" | |
# puts n | |
# end | |
# end | |
(1..200).select{|n| n % 7 == 0} | |
# n = 1 | |
# while n < upto | |
# puts n | |
# n += 7 | |
# end | |
# n = 0 | |
# while (n * 7) < upto | |
# puts n * 7 | |
# n += 1 | |
# end | |
(200/7).times{|n| puts (n + 1) * 7} | |
end | |
while true | |
puts "Please type A or B" | |
puts "A - Display 1 to 100" | |
puts "B - Display multiples of 7" | |
# Get the user's choice | |
choice = gets.chomp | |
# Run the method for the users choice | |
case choice.upcase | |
when 'A' | |
puts "OK, I'll Display 1 to 100" | |
display_to_hundred | |
when 'B' | |
puts "OK, I'll Display multples of 7 up to 200" | |
display_multiples_of_seven(200) | |
else | |
puts "I Dont know how to '#{choice}'!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment