Skip to content

Instantly share code, notes, and snippets.

@jkallner
jkallner / prime_numbers.rb
Created August 25, 2013 20:49
Code finds all prime numbers between two submitted numbers.
#!/usr/bin/env ruby
#Initial display the tell the user what the program does and then asks for input
puts "This program will find all the prime numbers between the two numbers you input."
puts "Please enter two numbers to search between other than 0 of course :)"
puts "Enter number 1:"
number_1 = gets.to_i
puts "Enter number 2:"
number_2 = gets.to_i
#This loop ensures that the number entered is not 0
@jkallner
jkallner / prime.rb
Last active December 21, 2015 16:09
Updated with checking for all primes between 2 input numbers
#!/usr/bin/env ruby
#Initial display the tell the user what the program does and then asks for input
puts "This program will find all the prime numbers between the two numbers you input."
puts "Please enter two numbers to search between other than 0 of course :)"
puts "Enter number 1:"
number_1 = gets.to_i
puts "Enter number 2:"
number_2 = gets.to_i
#This loop ensures that the number entered is not 0
@jkallner
jkallner / test.rb
Last active December 21, 2015 10:09
Another example
#!/usr/bin/env ruby
puts "Please input the radius of the circle:"
input_radius = gets.to_f
# Keep looping until the user gives us a valid number
# Non number entires such as words would equate to 0 with the .to_f method above
while input_radius == 0
puts "Please try a number that doesn't equal 0"
puts "Please input the radius of the circle:"
input_radius = gets.to_f