In this article I would like to share with you a sample program that will ask the user to give a number and then our program will check if the given number is an odd or even using Ruby as our programming language.
I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.
Sample Program Output
Program Listing
odd_even.rb
# odd_even.rb
# Written By: Mr. Jake R. Pomperada, MAED-IT
# December 13, 2017
# Tool : Ruby and Sublime Text Editor
# Location : Bacolod City, Negros Occidental Philippines
# method to check odd and even numbers
def check_odd_even(input_number)
if input_number % 2 == 0
print "\n\n"
print "The value #{input_number} is an even number."
print "\n\n"
else
print "\n\n"
print "The value #{input_number} is an odd number."
print "\n\n"
end
end
val_input =""
answer = ""
until answer.downcase == "n" do
print "\n\n"
print "===== ODD AND EVEN NUMBER CHECKER IN RUBY ====="
print "\n\n"
print "Created by Mr. Jake R. Pomperada"
print "\n\n"
print "Give a number : "
val_input = gets.to_i
check_odd_even(val_input)
print "\n"
print "Do you want to continue Y/N ? : "
answer= gets.chop
end
print "\n\n"
print "End of Program"
print "\n\n"